
<!DOCTYPE html>

<html>
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>pymatgen.vis.structure_vtk &#8212; pymatgen 2020.7.3 documentation</title>
    <link rel="stylesheet" href="../../../_static/basic.css" type="text/css" />
    <link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
    <script id="documentation_options" data-url_root="../../../" src="../../../_static/documentation_options.js"></script>
    <script src="../../../_static/jquery.js"></script>
    <script src="../../../_static/underscore.js"></script>
    <script src="../../../_static/doctools.js"></script>
    <script src="../../../_static/language_data.js"></script>
    <script async="async" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.7/latest.js?config=TeX-AMS-MML_HTMLorMML"></script>
    <link rel="index" title="Index" href="../../../genindex.html" />
    <link rel="search" title="Search" href="../../../search.html" />
 
<script type="text/javascript">
  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-33990148-1']);
  _gaq.push(['_trackPageview']);
</script>

  </head><body>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="nav-item nav-item-0"><a href="../../../index.html">pymatgen 2020.7.3 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="../../index.html" >Module code</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="../../pymatgen.html" accesskey="U">pymatgen</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href="">pymatgen.vis.structure_vtk</a></li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
          <div class="body" role="main">
            
  <h1>Source code for pymatgen.vis.structure_vtk</h1><div class="highlight"><pre>
<span></span><span class="c1"># coding: utf-8</span>
<span class="c1"># Copyright (c) Pymatgen Development Team.</span>
<span class="c1"># Distributed under the terms of the MIT License.</span>


<span class="sd">&quot;&quot;&quot;</span>
<span class="sd">This module contains classes to wrap Python VTK to make nice molecular plots.</span>
<span class="sd">&quot;&quot;&quot;</span>

<span class="n">__author__</span> <span class="o">=</span> <span class="s2">&quot;Shyue Ping Ong&quot;</span>
<span class="n">__copyright__</span> <span class="o">=</span> <span class="s2">&quot;Copyright 2011, The Materials Project&quot;</span>
<span class="n">__version__</span> <span class="o">=</span> <span class="s2">&quot;0.1&quot;</span>
<span class="n">__maintainer__</span> <span class="o">=</span> <span class="s2">&quot;Shyue Ping Ong&quot;</span>
<span class="n">__email__</span> <span class="o">=</span> <span class="s2">&quot;shyuep@gmail.com&quot;</span>
<span class="n">__date__</span> <span class="o">=</span> <span class="s2">&quot;Nov 27, 2011&quot;</span>

<span class="kn">import</span> <span class="nn">os</span>
<span class="kn">import</span> <span class="nn">itertools</span>
<span class="kn">import</span> <span class="nn">math</span>
<span class="kn">import</span> <span class="nn">subprocess</span>
<span class="kn">import</span> <span class="nn">time</span>

<span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>

<span class="k">try</span><span class="p">:</span>
    <span class="kn">import</span> <span class="nn">vtk</span>
    <span class="kn">from</span> <span class="nn">vtk</span> <span class="kn">import</span> <span class="n">vtkInteractorStyleTrackballCamera</span>
<span class="k">except</span> <span class="ne">ImportError</span><span class="p">:</span>
    <span class="c1"># VTK not present. The Camera is to set object to avoid errors in unittest.</span>
    <span class="n">vtk</span> <span class="o">=</span> <span class="kc">None</span>
    <span class="n">vtkInteractorStyleTrackballCamera</span> <span class="o">=</span> <span class="nb">object</span>

<span class="kn">from</span> <span class="nn">monty.serialization</span> <span class="kn">import</span> <span class="n">loadfn</span>
<span class="kn">from</span> <span class="nn">monty.dev</span> <span class="kn">import</span> <span class="n">requires</span>

<span class="kn">from</span> <span class="nn">pymatgen.util.coord</span> <span class="kn">import</span> <span class="n">in_coord_list</span>
<span class="kn">from</span> <span class="nn">pymatgen.core.periodic_table</span> <span class="kn">import</span> <span class="n">Specie</span>
<span class="kn">from</span> <span class="nn">pymatgen.core.structure</span> <span class="kn">import</span> <span class="n">Structure</span>
<span class="kn">from</span> <span class="nn">pymatgen.core.sites</span> <span class="kn">import</span> <span class="n">PeriodicSite</span>

<span class="n">module_dir</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">dirname</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">abspath</span><span class="p">(</span><span class="vm">__file__</span><span class="p">))</span>
<span class="n">EL_COLORS</span> <span class="o">=</span> <span class="n">loadfn</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">module_dir</span><span class="p">,</span> <span class="s2">&quot;ElementColorSchemes.yaml&quot;</span><span class="p">))</span>


<div class="viewcode-block" id="StructureVis"><a class="viewcode-back" href="../../../pymatgen.vis.structure_vtk.html#pymatgen.vis.structure_vtk.StructureVis">[docs]</a><span class="k">class</span> <span class="nc">StructureVis</span><span class="p">:</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Provides Structure object visualization using VTK.</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="nd">@requires</span><span class="p">(</span><span class="n">vtk</span><span class="p">,</span> <span class="s2">&quot;Visualization requires the installation of VTK with &quot;</span>
                   <span class="s2">&quot;Python bindings.&quot;</span><span class="p">)</span>
    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">element_color_mapping</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">show_unit_cell</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span>
                 <span class="n">show_bonds</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">show_polyhedron</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span>
                 <span class="n">poly_radii_tol_factor</span><span class="o">=</span><span class="mf">0.5</span><span class="p">,</span> <span class="n">excluded_bonding_elements</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Constructs a Structure Visualization.</span>

<span class="sd">        Args:</span>
<span class="sd">            element_color_mapping: Optional color mapping for the elements,</span>
<span class="sd">                as a dict of {symbol: rgb tuple}. For example, {&quot;Fe&quot;: (255,</span>
<span class="sd">                123,0), ....} If None is specified, a default based on</span>
<span class="sd">                Jmol&quot;s color scheme is used.</span>
<span class="sd">            show_unit_cell: Set to False to not show the unit cell</span>
<span class="sd">                boundaries. Defaults to True.</span>
<span class="sd">            show_bonds: Set to True to show bonds. Defaults to True.</span>
<span class="sd">            show_polyhedron: Set to True to show polyhedrons. Defaults to</span>
<span class="sd">                False.</span>
<span class="sd">            poly_radii_tol_factor: The polyhedron and bonding code uses the</span>
<span class="sd">                ionic radii of the elements or species to determine if two</span>
<span class="sd">                atoms are bonded. This specifies a tolerance scaling factor</span>
<span class="sd">                such that atoms which are (1 + poly_radii_tol_factor) * sum</span>
<span class="sd">                of ionic radii apart are still considered as bonded.</span>
<span class="sd">            excluded_bonding_elements: List of atom types to exclude from</span>
<span class="sd">                bonding determination. Defaults to an empty list. Useful</span>
<span class="sd">                when trying to visualize a certain atom type in the</span>
<span class="sd">                framework (e.g., Li in a Li-ion battery cathode material).</span>

<span class="sd">        Useful keyboard shortcuts implemented.</span>
<span class="sd">            h : Show help</span>
<span class="sd">            A/a : Increase/decrease cell by one unit vector in a-direction</span>
<span class="sd">            B/b : Increase/decrease cell by one unit vector in b-direction</span>
<span class="sd">            C/c : Increase/decrease cell by one unit vector in c-direction</span>
<span class="sd">            # : Toggle showing of polyhedrons</span>
<span class="sd">            - : Toggle showing of bonds</span>
<span class="sd">            [ : Decrease poly_radii_tol_factor by 0.05</span>
<span class="sd">            ] : Increase poly_radii_tol_factor by 0.05</span>
<span class="sd">            r : Reset camera direction</span>
<span class="sd">            o : Orthogonalize structure</span>
<span class="sd">            Up/Down : Rotate view along Up direction by 90 clock/anticlockwise</span>
<span class="sd">            Left/right : Rotate view along camera direction by 90</span>
<span class="sd">            clock/anticlockwise</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="c1"># create a rendering window and renderer</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">ren</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkRenderer</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">ren_win</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkRenderWindow</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">ren_win</span><span class="o">.</span><span class="n">AddRenderer</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">ren</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">ren</span><span class="o">.</span><span class="n">SetBackground</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">title</span> <span class="o">=</span> <span class="s2">&quot;Structure Visualizer&quot;</span>
        <span class="c1"># create a renderwindowinteractor</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">iren</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkRenderWindowInteractor</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">iren</span><span class="o">.</span><span class="n">SetRenderWindow</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">ren_win</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">mapper_map</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">structure</span> <span class="o">=</span> <span class="kc">None</span>

        <span class="k">if</span> <span class="n">element_color_mapping</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">el_color_mapping</span> <span class="o">=</span> <span class="n">element_color_mapping</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">el_color_mapping</span> <span class="o">=</span> <span class="n">EL_COLORS</span><span class="p">[</span><span class="s2">&quot;VESTA&quot;</span><span class="p">]</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">show_unit_cell</span> <span class="o">=</span> <span class="n">show_unit_cell</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">show_bonds</span> <span class="o">=</span> <span class="n">show_bonds</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">show_polyhedron</span> <span class="o">=</span> <span class="n">show_polyhedron</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">poly_radii_tol_factor</span> <span class="o">=</span> <span class="n">poly_radii_tol_factor</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">excluded_bonding_elements</span> <span class="o">=</span> <span class="n">excluded_bonding_elements</span> <span class="k">if</span> \
            <span class="n">excluded_bonding_elements</span> <span class="k">else</span> <span class="p">[]</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">show_help</span> <span class="o">=</span> <span class="kc">True</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">supercell</span> <span class="o">=</span> <span class="p">[[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">]]</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">redraw</span><span class="p">()</span>

        <span class="n">style</span> <span class="o">=</span> <span class="n">StructureInteractorStyle</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">iren</span><span class="o">.</span><span class="n">SetInteractorStyle</span><span class="p">(</span><span class="n">style</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">ren</span><span class="o">.</span><span class="n">parent</span> <span class="o">=</span> <span class="bp">self</span>

<div class="viewcode-block" id="StructureVis.rotate_view"><a class="viewcode-back" href="../../../pymatgen.vis.structure_vtk.html#pymatgen.vis.structure_vtk.StructureVis.rotate_view">[docs]</a>    <span class="k">def</span> <span class="nf">rotate_view</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">axis_ind</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">angle</span><span class="o">=</span><span class="mi">0</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Rotate the camera view.</span>

<span class="sd">        Args:</span>
<span class="sd">            axis_ind: Index of axis to rotate. Defaults to 0, i.e., a-axis.</span>
<span class="sd">            angle: Angle to rotate by. Defaults to 0.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">camera</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">ren</span><span class="o">.</span><span class="n">GetActiveCamera</span><span class="p">()</span>
        <span class="k">if</span> <span class="n">axis_ind</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
            <span class="n">camera</span><span class="o">.</span><span class="n">Roll</span><span class="p">(</span><span class="n">angle</span><span class="p">)</span>
        <span class="k">elif</span> <span class="n">axis_ind</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span>
            <span class="n">camera</span><span class="o">.</span><span class="n">Azimuth</span><span class="p">(</span><span class="n">angle</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">camera</span><span class="o">.</span><span class="n">Pitch</span><span class="p">(</span><span class="n">angle</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">ren_win</span><span class="o">.</span><span class="n">Render</span><span class="p">()</span></div>

<div class="viewcode-block" id="StructureVis.write_image"><a class="viewcode-back" href="../../../pymatgen.vis.structure_vtk.html#pymatgen.vis.structure_vtk.StructureVis.write_image">[docs]</a>    <span class="k">def</span> <span class="nf">write_image</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">filename</span><span class="o">=</span><span class="s2">&quot;image.png&quot;</span><span class="p">,</span> <span class="n">magnification</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span>
                    <span class="n">image_format</span><span class="o">=</span><span class="s2">&quot;png&quot;</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Save render window to an image.</span>

<span class="sd">        Arguments:</span>
<span class="sd">            filename:</span>
<span class="sd">                filename to save to. Defaults to image.png.</span>
<span class="sd">            magnification:</span>
<span class="sd">                magnification. Use it to render high res images.</span>
<span class="sd">            image_format:</span>
<span class="sd">                choose between jpeg, png.  Png is the default.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">render_large</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkRenderLargeImage</span><span class="p">()</span>
        <span class="n">render_large</span><span class="o">.</span><span class="n">SetInput</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">ren</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">image_format</span> <span class="o">==</span> <span class="s2">&quot;jpeg&quot;</span><span class="p">:</span>
            <span class="n">writer</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkJPEGWriter</span><span class="p">()</span>
            <span class="n">writer</span><span class="o">.</span><span class="n">SetQuality</span><span class="p">(</span><span class="mi">80</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">writer</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkPNGWriter</span><span class="p">()</span>

        <span class="n">render_large</span><span class="o">.</span><span class="n">SetMagnification</span><span class="p">(</span><span class="n">magnification</span><span class="p">)</span>
        <span class="n">writer</span><span class="o">.</span><span class="n">SetFileName</span><span class="p">(</span><span class="n">filename</span><span class="p">)</span>

        <span class="n">writer</span><span class="o">.</span><span class="n">SetInputConnection</span><span class="p">(</span><span class="n">render_large</span><span class="o">.</span><span class="n">GetOutputPort</span><span class="p">())</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">ren_win</span><span class="o">.</span><span class="n">Render</span><span class="p">()</span>
        <span class="n">writer</span><span class="o">.</span><span class="n">Write</span><span class="p">()</span>
        <span class="k">del</span> <span class="n">render_large</span></div>

<div class="viewcode-block" id="StructureVis.redraw"><a class="viewcode-back" href="../../../pymatgen.vis.structure_vtk.html#pymatgen.vis.structure_vtk.StructureVis.redraw">[docs]</a>    <span class="k">def</span> <span class="nf">redraw</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">reset_camera</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Redraw the render window.</span>

<span class="sd">        Args:</span>
<span class="sd">            reset_camera: Set to True to reset the camera to a</span>
<span class="sd">                pre-determined default for each structure.  Defaults to False.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">ren</span><span class="o">.</span><span class="n">RemoveAllViewProps</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">picker</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">add_picker_fixed</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">helptxt_mapper</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkTextMapper</span><span class="p">()</span>
        <span class="n">tprops</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">helptxt_mapper</span><span class="o">.</span><span class="n">GetTextProperty</span><span class="p">()</span>
        <span class="n">tprops</span><span class="o">.</span><span class="n">SetFontSize</span><span class="p">(</span><span class="mi">14</span><span class="p">)</span>
        <span class="n">tprops</span><span class="o">.</span><span class="n">SetFontFamilyToTimes</span><span class="p">()</span>
        <span class="n">tprops</span><span class="o">.</span><span class="n">SetColor</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">structure</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">set_structure</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">structure</span><span class="p">,</span> <span class="n">reset_camera</span><span class="p">)</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">ren_win</span><span class="o">.</span><span class="n">Render</span><span class="p">()</span></div>

<div class="viewcode-block" id="StructureVis.orthongonalize_structure"><a class="viewcode-back" href="../../../pymatgen.vis.structure_vtk.html#pymatgen.vis.structure_vtk.StructureVis.orthongonalize_structure">[docs]</a>    <span class="k">def</span> <span class="nf">orthongonalize_structure</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Orthogonalize the structure.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">structure</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">set_structure</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">structure</span><span class="o">.</span><span class="n">copy</span><span class="p">(</span><span class="n">sanitize</span><span class="o">=</span><span class="kc">True</span><span class="p">))</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">ren_win</span><span class="o">.</span><span class="n">Render</span><span class="p">()</span></div>

<div class="viewcode-block" id="StructureVis.display_help"><a class="viewcode-back" href="../../../pymatgen.vis.structure_vtk.html#pymatgen.vis.structure_vtk.StructureVis.display_help">[docs]</a>    <span class="k">def</span> <span class="nf">display_help</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Display the help for various keyboard shortcuts.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">helptxt</span> <span class="o">=</span> <span class="p">[</span><span class="s2">&quot;h : Toggle help&quot;</span><span class="p">,</span>
                   <span class="s2">&quot;A/a, B/b or C/c : Increase/decrease cell by one a,&quot;</span>
                   <span class="s2">&quot; b or c unit vector&quot;</span><span class="p">,</span> <span class="s2">&quot;# : Toggle showing of polyhedrons&quot;</span><span class="p">,</span>
                   <span class="s2">&quot;-: Toggle showing of bonds&quot;</span><span class="p">,</span> <span class="s2">&quot;r : Reset camera direction&quot;</span><span class="p">,</span>
                   <span class="s2">&quot;[/]: Decrease or increase poly_radii_tol_factor &quot;</span>
                   <span class="s2">&quot;by 0.05. Value = &quot;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">poly_radii_tol_factor</span><span class="p">),</span>
                   <span class="s2">&quot;Up/Down: Rotate view along Up direction by 90 &quot;</span>
                   <span class="s2">&quot;clockwise/anticlockwise&quot;</span><span class="p">,</span>
                   <span class="s2">&quot;Left/right: Rotate view along camera direction by &quot;</span>
                   <span class="s2">&quot;90 clockwise/anticlockwise&quot;</span><span class="p">,</span> <span class="s2">&quot;s: Save view to image.png&quot;</span><span class="p">,</span>
                   <span class="s2">&quot;o: Orthogonalize structure&quot;</span><span class="p">]</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">helptxt_mapper</span><span class="o">.</span><span class="n">SetInput</span><span class="p">(</span><span class="s2">&quot;</span><span class="se">\n</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">helptxt</span><span class="p">))</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">helptxt_actor</span><span class="o">.</span><span class="n">SetPosition</span><span class="p">(</span><span class="mi">10</span><span class="p">,</span> <span class="mi">10</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">helptxt_actor</span><span class="o">.</span><span class="n">VisibilityOn</span><span class="p">()</span></div>

<div class="viewcode-block" id="StructureVis.set_structure"><a class="viewcode-back" href="../../../pymatgen.vis.structure_vtk.html#pymatgen.vis.structure_vtk.StructureVis.set_structure">[docs]</a>    <span class="k">def</span> <span class="nf">set_structure</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">structure</span><span class="p">,</span> <span class="n">reset_camera</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">to_unit_cell</span><span class="o">=</span><span class="kc">True</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Add a structure to the visualizer.</span>

<span class="sd">        Args:</span>
<span class="sd">            structure: structure to visualize</span>
<span class="sd">            reset_camera: Set to True to reset the camera to a default</span>
<span class="sd">                determined based on the structure.</span>
<span class="sd">            to_unit_cell: Whether or not to fall back sites into the unit cell.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">ren</span><span class="o">.</span><span class="n">RemoveAllViewProps</span><span class="p">()</span>

        <span class="n">has_lattice</span> <span class="o">=</span> <span class="nb">hasattr</span><span class="p">(</span><span class="n">structure</span><span class="p">,</span> <span class="s2">&quot;lattice&quot;</span><span class="p">)</span>

        <span class="k">if</span> <span class="n">has_lattice</span><span class="p">:</span>
            <span class="n">s</span> <span class="o">=</span> <span class="n">Structure</span><span class="o">.</span><span class="n">from_sites</span><span class="p">(</span><span class="n">structure</span><span class="p">,</span> <span class="n">to_unit_cell</span><span class="o">=</span><span class="n">to_unit_cell</span><span class="p">)</span>
            <span class="n">s</span><span class="o">.</span><span class="n">make_supercell</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">supercell</span><span class="p">,</span> <span class="n">to_unit_cell</span><span class="o">=</span><span class="n">to_unit_cell</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">s</span> <span class="o">=</span> <span class="n">structure</span>

        <span class="n">inc_coords</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="k">for</span> <span class="n">site</span> <span class="ow">in</span> <span class="n">s</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">add_site</span><span class="p">(</span><span class="n">site</span><span class="p">)</span>
            <span class="n">inc_coords</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">site</span><span class="o">.</span><span class="n">coords</span><span class="p">)</span>

        <span class="n">count</span> <span class="o">=</span> <span class="mi">0</span>
        <span class="n">labels</span> <span class="o">=</span> <span class="p">[</span><span class="s2">&quot;a&quot;</span><span class="p">,</span> <span class="s2">&quot;b&quot;</span><span class="p">,</span> <span class="s2">&quot;c&quot;</span><span class="p">]</span>
        <span class="n">colors</span> <span class="o">=</span> <span class="p">[(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">),</span> <span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">),</span> <span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">)]</span>

        <span class="k">if</span> <span class="n">has_lattice</span><span class="p">:</span>
            <span class="n">matrix</span> <span class="o">=</span> <span class="n">s</span><span class="o">.</span><span class="n">lattice</span><span class="o">.</span><span class="n">matrix</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">show_unit_cell</span> <span class="ow">and</span> <span class="n">has_lattice</span><span class="p">:</span>
            <span class="c1"># matrix = s.lattice.matrix</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">add_text</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span> <span class="s2">&quot;o&quot;</span><span class="p">)</span>
            <span class="k">for</span> <span class="n">vec</span> <span class="ow">in</span> <span class="n">matrix</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">add_line</span><span class="p">((</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">),</span> <span class="n">vec</span><span class="p">,</span> <span class="n">colors</span><span class="p">[</span><span class="n">count</span><span class="p">])</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">add_text</span><span class="p">(</span><span class="n">vec</span><span class="p">,</span> <span class="n">labels</span><span class="p">[</span><span class="n">count</span><span class="p">],</span> <span class="n">colors</span><span class="p">[</span><span class="n">count</span><span class="p">])</span>
                <span class="n">count</span> <span class="o">+=</span> <span class="mi">1</span>
            <span class="k">for</span> <span class="p">(</span><span class="n">vec1</span><span class="p">,</span> <span class="n">vec2</span><span class="p">)</span> <span class="ow">in</span> <span class="n">itertools</span><span class="o">.</span><span class="n">permutations</span><span class="p">(</span><span class="n">matrix</span><span class="p">,</span> <span class="mi">2</span><span class="p">):</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">add_line</span><span class="p">(</span><span class="n">vec1</span><span class="p">,</span> <span class="n">vec1</span> <span class="o">+</span> <span class="n">vec2</span><span class="p">)</span>
            <span class="k">for</span> <span class="p">(</span><span class="n">vec1</span><span class="p">,</span> <span class="n">vec2</span><span class="p">,</span> <span class="n">vec3</span><span class="p">)</span> <span class="ow">in</span> <span class="n">itertools</span><span class="o">.</span><span class="n">permutations</span><span class="p">(</span><span class="n">matrix</span><span class="p">,</span> <span class="mi">3</span><span class="p">):</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">add_line</span><span class="p">(</span><span class="n">vec1</span> <span class="o">+</span> <span class="n">vec2</span><span class="p">,</span> <span class="n">vec1</span> <span class="o">+</span> <span class="n">vec2</span> <span class="o">+</span> <span class="n">vec3</span><span class="p">)</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">show_bonds</span> <span class="ow">or</span> <span class="bp">self</span><span class="o">.</span><span class="n">show_polyhedron</span><span class="p">:</span>
            <span class="n">elements</span> <span class="o">=</span> <span class="nb">sorted</span><span class="p">(</span><span class="n">s</span><span class="o">.</span><span class="n">composition</span><span class="o">.</span><span class="n">elements</span><span class="p">,</span> <span class="n">key</span><span class="o">=</span><span class="k">lambda</span> <span class="n">a</span><span class="p">:</span> <span class="n">a</span><span class="o">.</span><span class="n">X</span><span class="p">)</span>
            <span class="n">anion</span> <span class="o">=</span> <span class="n">elements</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span>

            <span class="k">def</span> <span class="nf">contains_anion</span><span class="p">(</span><span class="n">site</span><span class="p">):</span>
                <span class="k">for</span> <span class="n">sp</span> <span class="ow">in</span> <span class="n">site</span><span class="o">.</span><span class="n">species</span><span class="o">.</span><span class="n">keys</span><span class="p">():</span>
                    <span class="k">if</span> <span class="n">sp</span><span class="o">.</span><span class="n">symbol</span> <span class="o">==</span> <span class="n">anion</span><span class="o">.</span><span class="n">symbol</span><span class="p">:</span>
                        <span class="k">return</span> <span class="kc">True</span>
                <span class="k">return</span> <span class="kc">False</span>

            <span class="n">anion_radius</span> <span class="o">=</span> <span class="n">anion</span><span class="o">.</span><span class="n">average_ionic_radius</span>
            <span class="k">for</span> <span class="n">site</span> <span class="ow">in</span> <span class="n">s</span><span class="p">:</span>
                <span class="n">exclude</span> <span class="o">=</span> <span class="kc">False</span>
                <span class="n">max_radius</span> <span class="o">=</span> <span class="mi">0</span>
                <span class="n">color</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">])</span>
                <span class="k">for</span> <span class="n">sp</span><span class="p">,</span> <span class="n">occu</span> <span class="ow">in</span> <span class="n">site</span><span class="o">.</span><span class="n">species</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
                    <span class="k">if</span> <span class="n">sp</span><span class="o">.</span><span class="n">symbol</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">excluded_bonding_elements</span> <span class="ow">or</span> <span class="n">sp</span> <span class="o">==</span> <span class="n">anion</span><span class="p">:</span>
                        <span class="n">exclude</span> <span class="o">=</span> <span class="kc">True</span>
                        <span class="k">break</span>
                    <span class="n">max_radius</span> <span class="o">=</span> <span class="nb">max</span><span class="p">(</span><span class="n">max_radius</span><span class="p">,</span> <span class="n">sp</span><span class="o">.</span><span class="n">average_ionic_radius</span><span class="p">)</span>
                    <span class="n">color</span> <span class="o">=</span> <span class="n">color</span> <span class="o">+</span> <span class="n">occu</span> <span class="o">*</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">el_color_mapping</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">sp</span><span class="o">.</span><span class="n">symbol</span><span class="p">,</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">]))</span>

                <span class="k">if</span> <span class="ow">not</span> <span class="n">exclude</span><span class="p">:</span>
                    <span class="n">max_radius</span> <span class="o">=</span> <span class="p">(</span><span class="mi">1</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">poly_radii_tol_factor</span><span class="p">)</span> <span class="o">*</span> <span class="p">(</span><span class="n">max_radius</span> <span class="o">+</span> <span class="n">anion_radius</span><span class="p">)</span>
                    <span class="n">nn</span> <span class="o">=</span> <span class="n">structure</span><span class="o">.</span><span class="n">get_neighbors</span><span class="p">(</span><span class="n">site</span><span class="p">,</span> <span class="nb">float</span><span class="p">(</span><span class="n">max_radius</span><span class="p">))</span>
                    <span class="n">nn_sites</span> <span class="o">=</span> <span class="p">[]</span>
                    <span class="k">for</span> <span class="n">neighbor</span> <span class="ow">in</span> <span class="n">nn</span><span class="p">:</span>
                        <span class="k">if</span> <span class="n">contains_anion</span><span class="p">(</span><span class="n">neighbor</span><span class="p">):</span>
                            <span class="n">nn_sites</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">neighbor</span><span class="p">)</span>
                            <span class="k">if</span> <span class="ow">not</span> <span class="n">in_coord_list</span><span class="p">(</span><span class="n">inc_coords</span><span class="p">,</span> <span class="n">neighbor</span><span class="o">.</span><span class="n">coords</span><span class="p">):</span>
                                <span class="bp">self</span><span class="o">.</span><span class="n">add_site</span><span class="p">(</span><span class="n">neighbor</span><span class="p">)</span>
                    <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">show_bonds</span><span class="p">:</span>
                        <span class="bp">self</span><span class="o">.</span><span class="n">add_bonds</span><span class="p">(</span><span class="n">nn_sites</span><span class="p">,</span> <span class="n">site</span><span class="p">)</span>
                    <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">show_polyhedron</span><span class="p">:</span>
                        <span class="n">color</span> <span class="o">=</span> <span class="p">[</span><span class="n">i</span> <span class="o">/</span> <span class="mi">255</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">color</span><span class="p">]</span>
                        <span class="bp">self</span><span class="o">.</span><span class="n">add_polyhedron</span><span class="p">(</span><span class="n">nn_sites</span><span class="p">,</span> <span class="n">site</span><span class="p">,</span> <span class="n">color</span><span class="p">)</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">show_help</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">helptxt_actor</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkActor2D</span><span class="p">()</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">helptxt_actor</span><span class="o">.</span><span class="n">VisibilityOn</span><span class="p">()</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">helptxt_actor</span><span class="o">.</span><span class="n">SetMapper</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">helptxt_mapper</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">ren</span><span class="o">.</span><span class="n">AddActor</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">helptxt_actor</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">display_help</span><span class="p">()</span>

        <span class="n">camera</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">ren</span><span class="o">.</span><span class="n">GetActiveCamera</span><span class="p">()</span>
        <span class="k">if</span> <span class="n">reset_camera</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">has_lattice</span><span class="p">:</span>
                <span class="c1"># Adjust the camera for best viewing</span>
                <span class="n">lengths</span> <span class="o">=</span> <span class="n">s</span><span class="o">.</span><span class="n">lattice</span><span class="o">.</span><span class="n">abc</span>
                <span class="n">pos</span> <span class="o">=</span> <span class="p">(</span><span class="n">matrix</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">+</span> <span class="n">matrix</span><span class="p">[</span><span class="mi">2</span><span class="p">])</span> <span class="o">*</span> <span class="mf">0.5</span> <span class="o">+</span> <span class="n">matrix</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">*</span> <span class="nb">max</span><span class="p">(</span><span class="n">lengths</span><span class="p">)</span> <span class="o">/</span> <span class="n">lengths</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">*</span> <span class="mf">3.5</span>
                <span class="n">camera</span><span class="o">.</span><span class="n">SetPosition</span><span class="p">(</span><span class="n">pos</span><span class="p">)</span>
                <span class="n">camera</span><span class="o">.</span><span class="n">SetViewUp</span><span class="p">(</span><span class="n">matrix</span><span class="p">[</span><span class="mi">2</span><span class="p">])</span>
                <span class="n">camera</span><span class="o">.</span><span class="n">SetFocalPoint</span><span class="p">((</span><span class="n">matrix</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">+</span> <span class="n">matrix</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">+</span> <span class="n">matrix</span><span class="p">[</span><span class="mi">2</span><span class="p">])</span> <span class="o">*</span> <span class="mf">0.5</span><span class="p">)</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">origin</span> <span class="o">=</span> <span class="n">s</span><span class="o">.</span><span class="n">center_of_mass</span>
                <span class="n">max_site</span> <span class="o">=</span> <span class="nb">max</span><span class="p">(</span>
                    <span class="n">s</span><span class="p">,</span> <span class="n">key</span><span class="o">=</span><span class="k">lambda</span> <span class="n">site</span><span class="p">:</span> <span class="n">site</span><span class="o">.</span><span class="n">distance_from_point</span><span class="p">(</span><span class="n">origin</span><span class="p">))</span>
                <span class="n">camera</span><span class="o">.</span><span class="n">SetPosition</span><span class="p">(</span><span class="n">origin</span> <span class="o">+</span> <span class="mi">5</span> <span class="o">*</span> <span class="p">(</span><span class="n">max_site</span><span class="o">.</span><span class="n">coords</span> <span class="o">-</span> <span class="n">origin</span><span class="p">))</span>
                <span class="n">camera</span><span class="o">.</span><span class="n">SetFocalPoint</span><span class="p">(</span><span class="n">s</span><span class="o">.</span><span class="n">center_of_mass</span><span class="p">)</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">structure</span> <span class="o">=</span> <span class="n">structure</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">title</span> <span class="o">=</span> <span class="n">s</span><span class="o">.</span><span class="n">composition</span><span class="o">.</span><span class="n">formula</span></div>

<div class="viewcode-block" id="StructureVis.zoom"><a class="viewcode-back" href="../../../pymatgen.vis.structure_vtk.html#pymatgen.vis.structure_vtk.StructureVis.zoom">[docs]</a>    <span class="k">def</span> <span class="nf">zoom</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">factor</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Zoom the camera view by a factor.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">camera</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">ren</span><span class="o">.</span><span class="n">GetActiveCamera</span><span class="p">()</span>
        <span class="n">camera</span><span class="o">.</span><span class="n">Zoom</span><span class="p">(</span><span class="n">factor</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">ren_win</span><span class="o">.</span><span class="n">Render</span><span class="p">()</span></div>

<div class="viewcode-block" id="StructureVis.show"><a class="viewcode-back" href="../../../pymatgen.vis.structure_vtk.html#pymatgen.vis.structure_vtk.StructureVis.show">[docs]</a>    <span class="k">def</span> <span class="nf">show</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Display the visualizer.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">iren</span><span class="o">.</span><span class="n">Initialize</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">ren_win</span><span class="o">.</span><span class="n">SetSize</span><span class="p">(</span><span class="mi">800</span><span class="p">,</span> <span class="mi">800</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">ren_win</span><span class="o">.</span><span class="n">SetWindowName</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">title</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">ren_win</span><span class="o">.</span><span class="n">Render</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">iren</span><span class="o">.</span><span class="n">Start</span><span class="p">()</span></div>

<div class="viewcode-block" id="StructureVis.add_site"><a class="viewcode-back" href="../../../pymatgen.vis.structure_vtk.html#pymatgen.vis.structure_vtk.StructureVis.add_site">[docs]</a>    <span class="k">def</span> <span class="nf">add_site</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">site</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Add a site to the render window. The site is displayed as a sphere, the</span>
<span class="sd">        color of which is determined based on the element. Partially occupied</span>
<span class="sd">        sites are displayed as a single element color, though the site info</span>
<span class="sd">        still shows the partial occupancy.</span>

<span class="sd">        Args:</span>
<span class="sd">            site: Site to add.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">start_angle</span> <span class="o">=</span> <span class="mi">0</span>
        <span class="n">radius</span> <span class="o">=</span> <span class="mi">0</span>
        <span class="n">total_occu</span> <span class="o">=</span> <span class="mi">0</span>

        <span class="k">for</span> <span class="n">specie</span><span class="p">,</span> <span class="n">occu</span> <span class="ow">in</span> <span class="n">site</span><span class="o">.</span><span class="n">species</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
            <span class="n">radius</span> <span class="o">+=</span> <span class="n">occu</span> <span class="o">*</span> <span class="p">(</span><span class="n">specie</span><span class="o">.</span><span class="n">ionic_radius</span>
                              <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">specie</span><span class="p">,</span> <span class="n">Specie</span><span class="p">)</span> <span class="ow">and</span> <span class="n">specie</span><span class="o">.</span><span class="n">ionic_radius</span>
                              <span class="k">else</span> <span class="n">specie</span><span class="o">.</span><span class="n">average_ionic_radius</span><span class="p">)</span>
            <span class="n">total_occu</span> <span class="o">+=</span> <span class="n">occu</span>

        <span class="n">vis_radius</span> <span class="o">=</span> <span class="mf">0.2</span> <span class="o">+</span> <span class="mf">0.002</span> <span class="o">*</span> <span class="n">radius</span>

        <span class="k">for</span> <span class="n">specie</span><span class="p">,</span> <span class="n">occu</span> <span class="ow">in</span> <span class="n">site</span><span class="o">.</span><span class="n">species</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
            <span class="k">if</span> <span class="ow">not</span> <span class="n">specie</span><span class="p">:</span>
                <span class="n">color</span> <span class="o">=</span> <span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
            <span class="k">elif</span> <span class="n">specie</span><span class="o">.</span><span class="n">symbol</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">el_color_mapping</span><span class="p">:</span>
                <span class="n">color</span> <span class="o">=</span> <span class="p">[</span><span class="n">i</span> <span class="o">/</span> <span class="mi">255</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">el_color_mapping</span><span class="p">[</span><span class="n">specie</span><span class="o">.</span><span class="n">symbol</span><span class="p">]]</span>
            <span class="n">mapper</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">add_partial_sphere</span><span class="p">(</span><span class="n">site</span><span class="o">.</span><span class="n">coords</span><span class="p">,</span> <span class="n">vis_radius</span><span class="p">,</span> <span class="n">color</span><span class="p">,</span>
                                             <span class="n">start_angle</span><span class="p">,</span> <span class="n">start_angle</span> <span class="o">+</span> <span class="mi">360</span> <span class="o">*</span> <span class="n">occu</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">mapper_map</span><span class="p">[</span><span class="n">mapper</span><span class="p">]</span> <span class="o">=</span> <span class="p">[</span><span class="n">site</span><span class="p">]</span>
            <span class="n">start_angle</span> <span class="o">+=</span> <span class="mi">360</span> <span class="o">*</span> <span class="n">occu</span>

        <span class="k">if</span> <span class="n">total_occu</span> <span class="o">&lt;</span> <span class="mi">1</span><span class="p">:</span>
            <span class="n">mapper</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">add_partial_sphere</span><span class="p">(</span><span class="n">site</span><span class="o">.</span><span class="n">coords</span><span class="p">,</span> <span class="n">vis_radius</span><span class="p">,</span> <span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">),</span>
                                             <span class="n">start_angle</span><span class="p">,</span> <span class="n">start_angle</span> <span class="o">+</span> <span class="mi">360</span> <span class="o">*</span> <span class="p">(</span><span class="mi">1</span> <span class="o">-</span> <span class="n">total_occu</span><span class="p">))</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">mapper_map</span><span class="p">[</span><span class="n">mapper</span><span class="p">]</span> <span class="o">=</span> <span class="p">[</span><span class="n">site</span><span class="p">]</span></div>

<div class="viewcode-block" id="StructureVis.add_partial_sphere"><a class="viewcode-back" href="../../../pymatgen.vis.structure_vtk.html#pymatgen.vis.structure_vtk.StructureVis.add_partial_sphere">[docs]</a>    <span class="k">def</span> <span class="nf">add_partial_sphere</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">coords</span><span class="p">,</span> <span class="n">radius</span><span class="p">,</span> <span class="n">color</span><span class="p">,</span> <span class="n">start</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">end</span><span class="o">=</span><span class="mi">360</span><span class="p">,</span>
                           <span class="n">opacity</span><span class="o">=</span><span class="mf">1.0</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Adding a partial sphere (to display partial occupancies.</span>

<span class="sd">        Args:</span>
<span class="sd">            coords (nd.array): Coordinates</span>
<span class="sd">            radius (float): Radius of sphere</span>
<span class="sd">            color (): Color of sphere.</span>
<span class="sd">            start (float): Starting angle.</span>
<span class="sd">            end (float): Ending angle.</span>
<span class="sd">            opacity (float): Opacity.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">sphere</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkSphereSource</span><span class="p">()</span>
        <span class="n">sphere</span><span class="o">.</span><span class="n">SetCenter</span><span class="p">(</span><span class="n">coords</span><span class="p">)</span>
        <span class="n">sphere</span><span class="o">.</span><span class="n">SetRadius</span><span class="p">(</span><span class="n">radius</span><span class="p">)</span>
        <span class="n">sphere</span><span class="o">.</span><span class="n">SetThetaResolution</span><span class="p">(</span><span class="mi">18</span><span class="p">)</span>
        <span class="n">sphere</span><span class="o">.</span><span class="n">SetPhiResolution</span><span class="p">(</span><span class="mi">18</span><span class="p">)</span>
        <span class="n">sphere</span><span class="o">.</span><span class="n">SetStartTheta</span><span class="p">(</span><span class="n">start</span><span class="p">)</span>
        <span class="n">sphere</span><span class="o">.</span><span class="n">SetEndTheta</span><span class="p">(</span><span class="n">end</span><span class="p">)</span>

        <span class="n">mapper</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkPolyDataMapper</span><span class="p">()</span>
        <span class="n">mapper</span><span class="o">.</span><span class="n">SetInputConnection</span><span class="p">(</span><span class="n">sphere</span><span class="o">.</span><span class="n">GetOutputPort</span><span class="p">())</span>
        <span class="n">actor</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkActor</span><span class="p">()</span>
        <span class="n">actor</span><span class="o">.</span><span class="n">SetMapper</span><span class="p">(</span><span class="n">mapper</span><span class="p">)</span>
        <span class="n">actor</span><span class="o">.</span><span class="n">GetProperty</span><span class="p">()</span><span class="o">.</span><span class="n">SetColor</span><span class="p">(</span><span class="n">color</span><span class="p">)</span>
        <span class="n">actor</span><span class="o">.</span><span class="n">GetProperty</span><span class="p">()</span><span class="o">.</span><span class="n">SetOpacity</span><span class="p">(</span><span class="n">opacity</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">ren</span><span class="o">.</span><span class="n">AddActor</span><span class="p">(</span><span class="n">actor</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">mapper</span></div>

<div class="viewcode-block" id="StructureVis.add_text"><a class="viewcode-back" href="../../../pymatgen.vis.structure_vtk.html#pymatgen.vis.structure_vtk.StructureVis.add_text">[docs]</a>    <span class="k">def</span> <span class="nf">add_text</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">coords</span><span class="p">,</span> <span class="n">text</span><span class="p">,</span> <span class="n">color</span><span class="o">=</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">)):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Add text at a coordinate.</span>

<span class="sd">        Args:</span>
<span class="sd">            coords: Coordinates to add text at.</span>
<span class="sd">            text: Text to place.</span>
<span class="sd">            color: Color for text as RGB. Defaults to black.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">source</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkVectorText</span><span class="p">()</span>
        <span class="n">source</span><span class="o">.</span><span class="n">SetText</span><span class="p">(</span><span class="n">text</span><span class="p">)</span>
        <span class="n">mapper</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkPolyDataMapper</span><span class="p">()</span>
        <span class="n">mapper</span><span class="o">.</span><span class="n">SetInputConnection</span><span class="p">(</span><span class="n">source</span><span class="o">.</span><span class="n">GetOutputPort</span><span class="p">())</span>
        <span class="n">follower</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkFollower</span><span class="p">()</span>
        <span class="n">follower</span><span class="o">.</span><span class="n">SetMapper</span><span class="p">(</span><span class="n">mapper</span><span class="p">)</span>
        <span class="n">follower</span><span class="o">.</span><span class="n">GetProperty</span><span class="p">()</span><span class="o">.</span><span class="n">SetColor</span><span class="p">(</span><span class="n">color</span><span class="p">)</span>
        <span class="n">follower</span><span class="o">.</span><span class="n">SetPosition</span><span class="p">(</span><span class="n">coords</span><span class="p">)</span>
        <span class="n">follower</span><span class="o">.</span><span class="n">SetScale</span><span class="p">(</span><span class="mf">0.5</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">ren</span><span class="o">.</span><span class="n">AddActor</span><span class="p">(</span><span class="n">follower</span><span class="p">)</span>
        <span class="n">follower</span><span class="o">.</span><span class="n">SetCamera</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">ren</span><span class="o">.</span><span class="n">GetActiveCamera</span><span class="p">())</span></div>

<div class="viewcode-block" id="StructureVis.add_line"><a class="viewcode-back" href="../../../pymatgen.vis.structure_vtk.html#pymatgen.vis.structure_vtk.StructureVis.add_line">[docs]</a>    <span class="k">def</span> <span class="nf">add_line</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">start</span><span class="p">,</span> <span class="n">end</span><span class="p">,</span> <span class="n">color</span><span class="o">=</span><span class="p">(</span><span class="mf">0.5</span><span class="p">,</span> <span class="mf">0.5</span><span class="p">,</span> <span class="mf">0.5</span><span class="p">),</span> <span class="n">width</span><span class="o">=</span><span class="mi">1</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Adds a line.</span>

<span class="sd">        Args:</span>
<span class="sd">            start: Starting coordinates for line.</span>
<span class="sd">            end: Ending coordinates for line.</span>
<span class="sd">            color: Color for text as RGB. Defaults to grey.</span>
<span class="sd">            width: Width of line. Defaults to 1.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">source</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkLineSource</span><span class="p">()</span>
        <span class="n">source</span><span class="o">.</span><span class="n">SetPoint1</span><span class="p">(</span><span class="n">start</span><span class="p">)</span>
        <span class="n">source</span><span class="o">.</span><span class="n">SetPoint2</span><span class="p">(</span><span class="n">end</span><span class="p">)</span>

        <span class="n">vertexIDs</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkStringArray</span><span class="p">()</span>
        <span class="n">vertexIDs</span><span class="o">.</span><span class="n">SetNumberOfComponents</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
        <span class="n">vertexIDs</span><span class="o">.</span><span class="n">SetName</span><span class="p">(</span><span class="s2">&quot;VertexIDs&quot;</span><span class="p">)</span>
        <span class="c1"># Set the vertex labels</span>
        <span class="n">vertexIDs</span><span class="o">.</span><span class="n">InsertNextValue</span><span class="p">(</span><span class="s2">&quot;a&quot;</span><span class="p">)</span>
        <span class="n">vertexIDs</span><span class="o">.</span><span class="n">InsertNextValue</span><span class="p">(</span><span class="s2">&quot;b&quot;</span><span class="p">)</span>
        <span class="n">source</span><span class="o">.</span><span class="n">GetOutput</span><span class="p">()</span><span class="o">.</span><span class="n">GetPointData</span><span class="p">()</span><span class="o">.</span><span class="n">AddArray</span><span class="p">(</span><span class="n">vertexIDs</span><span class="p">)</span>

        <span class="n">mapper</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkPolyDataMapper</span><span class="p">()</span>
        <span class="n">mapper</span><span class="o">.</span><span class="n">SetInputConnection</span><span class="p">(</span><span class="n">source</span><span class="o">.</span><span class="n">GetOutputPort</span><span class="p">())</span>
        <span class="n">actor</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkActor</span><span class="p">()</span>
        <span class="n">actor</span><span class="o">.</span><span class="n">SetMapper</span><span class="p">(</span><span class="n">mapper</span><span class="p">)</span>
        <span class="n">actor</span><span class="o">.</span><span class="n">GetProperty</span><span class="p">()</span><span class="o">.</span><span class="n">SetColor</span><span class="p">(</span><span class="n">color</span><span class="p">)</span>
        <span class="n">actor</span><span class="o">.</span><span class="n">GetProperty</span><span class="p">()</span><span class="o">.</span><span class="n">SetLineWidth</span><span class="p">(</span><span class="n">width</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">ren</span><span class="o">.</span><span class="n">AddActor</span><span class="p">(</span><span class="n">actor</span><span class="p">)</span></div>

<div class="viewcode-block" id="StructureVis.add_polyhedron"><a class="viewcode-back" href="../../../pymatgen.vis.structure_vtk.html#pymatgen.vis.structure_vtk.StructureVis.add_polyhedron">[docs]</a>    <span class="k">def</span> <span class="nf">add_polyhedron</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">neighbors</span><span class="p">,</span> <span class="n">center</span><span class="p">,</span> <span class="n">color</span><span class="p">,</span> <span class="n">opacity</span><span class="o">=</span><span class="mf">1.0</span><span class="p">,</span>
                       <span class="n">draw_edges</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">edges_color</span><span class="o">=</span><span class="p">[</span><span class="mf">0.0</span><span class="p">,</span> <span class="mf">0.0</span><span class="p">,</span> <span class="mf">0.0</span><span class="p">],</span>
                       <span class="n">edges_linewidth</span><span class="o">=</span><span class="mi">2</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Adds a polyhedron.</span>

<span class="sd">        Args:</span>
<span class="sd">            neighbors: Neighbors of the polyhedron (the vertices).</span>
<span class="sd">            center: The atom in the center of the polyhedron.</span>
<span class="sd">            color: Color for text as RGB.</span>
<span class="sd">            opacity: Opacity of the polyhedron</span>
<span class="sd">            draw_edges: If set to True, the a line will be drawn at each edge</span>
<span class="sd">            edges_color: Color of the line for the edges</span>
<span class="sd">            edges_linewidth: Width of the line drawn for the edges</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">points</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkPoints</span><span class="p">()</span>
        <span class="n">conv</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkConvexPointSet</span><span class="p">()</span>
        <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">neighbors</span><span class="p">)):</span>
            <span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">z</span> <span class="o">=</span> <span class="n">neighbors</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">coords</span>
            <span class="n">points</span><span class="o">.</span><span class="n">InsertPoint</span><span class="p">(</span><span class="n">i</span><span class="p">,</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">z</span><span class="p">)</span>
            <span class="n">conv</span><span class="o">.</span><span class="n">GetPointIds</span><span class="p">()</span><span class="o">.</span><span class="n">InsertId</span><span class="p">(</span><span class="n">i</span><span class="p">,</span> <span class="n">i</span><span class="p">)</span>
        <span class="n">grid</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkUnstructuredGrid</span><span class="p">()</span>
        <span class="n">grid</span><span class="o">.</span><span class="n">Allocate</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
        <span class="n">grid</span><span class="o">.</span><span class="n">InsertNextCell</span><span class="p">(</span><span class="n">conv</span><span class="o">.</span><span class="n">GetCellType</span><span class="p">(),</span> <span class="n">conv</span><span class="o">.</span><span class="n">GetPointIds</span><span class="p">())</span>
        <span class="n">grid</span><span class="o">.</span><span class="n">SetPoints</span><span class="p">(</span><span class="n">points</span><span class="p">)</span>

        <span class="n">dsm</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkDataSetMapper</span><span class="p">()</span>
        <span class="n">polysites</span> <span class="o">=</span> <span class="p">[</span><span class="n">center</span><span class="p">]</span>
        <span class="n">polysites</span><span class="o">.</span><span class="n">extend</span><span class="p">(</span><span class="n">neighbors</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">mapper_map</span><span class="p">[</span><span class="n">dsm</span><span class="p">]</span> <span class="o">=</span> <span class="n">polysites</span>
        <span class="k">if</span> <span class="n">vtk</span><span class="o">.</span><span class="n">VTK_MAJOR_VERSION</span> <span class="o">&lt;=</span> <span class="mi">5</span><span class="p">:</span>
            <span class="n">dsm</span><span class="o">.</span><span class="n">SetInputConnection</span><span class="p">(</span><span class="n">grid</span><span class="o">.</span><span class="n">GetProducerPort</span><span class="p">())</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">dsm</span><span class="o">.</span><span class="n">SetInputData</span><span class="p">(</span><span class="n">grid</span><span class="p">)</span>
        <span class="n">ac</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkActor</span><span class="p">()</span>
        <span class="c1"># ac.SetMapper(mapHull)</span>
        <span class="n">ac</span><span class="o">.</span><span class="n">SetMapper</span><span class="p">(</span><span class="n">dsm</span><span class="p">)</span>
        <span class="n">ac</span><span class="o">.</span><span class="n">GetProperty</span><span class="p">()</span><span class="o">.</span><span class="n">SetOpacity</span><span class="p">(</span><span class="n">opacity</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">color</span> <span class="o">==</span> <span class="s1">&#39;element&#39;</span><span class="p">:</span>
            <span class="c1"># If partial occupations are involved, the color of the specie with</span>
            <span class="c1"># the highest occupation is used</span>
            <span class="n">myoccu</span> <span class="o">=</span> <span class="mf">0.0</span>
            <span class="k">for</span> <span class="n">specie</span><span class="p">,</span> <span class="n">occu</span> <span class="ow">in</span> <span class="n">center</span><span class="o">.</span><span class="n">species</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
                <span class="k">if</span> <span class="n">occu</span> <span class="o">&gt;</span> <span class="n">myoccu</span><span class="p">:</span>
                    <span class="n">myspecie</span> <span class="o">=</span> <span class="n">specie</span>
                    <span class="n">myoccu</span> <span class="o">=</span> <span class="n">occu</span>
            <span class="n">color</span> <span class="o">=</span> <span class="p">[</span><span class="n">i</span> <span class="o">/</span> <span class="mi">255</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">el_color_mapping</span><span class="p">[</span><span class="n">myspecie</span><span class="o">.</span><span class="n">symbol</span><span class="p">]]</span>
            <span class="n">ac</span><span class="o">.</span><span class="n">GetProperty</span><span class="p">()</span><span class="o">.</span><span class="n">SetColor</span><span class="p">(</span><span class="n">color</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">ac</span><span class="o">.</span><span class="n">GetProperty</span><span class="p">()</span><span class="o">.</span><span class="n">SetColor</span><span class="p">(</span><span class="n">color</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">draw_edges</span><span class="p">:</span>
            <span class="n">ac</span><span class="o">.</span><span class="n">GetProperty</span><span class="p">()</span><span class="o">.</span><span class="n">SetEdgeColor</span><span class="p">(</span><span class="n">edges_color</span><span class="p">)</span>
            <span class="n">ac</span><span class="o">.</span><span class="n">GetProperty</span><span class="p">()</span><span class="o">.</span><span class="n">SetLineWidth</span><span class="p">(</span><span class="n">edges_linewidth</span><span class="p">)</span>
            <span class="n">ac</span><span class="o">.</span><span class="n">GetProperty</span><span class="p">()</span><span class="o">.</span><span class="n">EdgeVisibilityOn</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">ren</span><span class="o">.</span><span class="n">AddActor</span><span class="p">(</span><span class="n">ac</span><span class="p">)</span></div>

<div class="viewcode-block" id="StructureVis.add_triangle"><a class="viewcode-back" href="../../../pymatgen.vis.structure_vtk.html#pymatgen.vis.structure_vtk.StructureVis.add_triangle">[docs]</a>    <span class="k">def</span> <span class="nf">add_triangle</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">neighbors</span><span class="p">,</span> <span class="n">color</span><span class="p">,</span> <span class="n">center</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">opacity</span><span class="o">=</span><span class="mf">0.4</span><span class="p">,</span>
                     <span class="n">draw_edges</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">edges_color</span><span class="o">=</span><span class="p">[</span><span class="mf">0.0</span><span class="p">,</span> <span class="mf">0.0</span><span class="p">,</span> <span class="mf">0.0</span><span class="p">],</span>
                     <span class="n">edges_linewidth</span><span class="o">=</span><span class="mi">2</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Adds a triangular surface between three atoms.</span>

<span class="sd">        Args:</span>
<span class="sd">            atoms: Atoms between which a triangle will be drawn.</span>
<span class="sd">            color: Color for triangle as RGB.</span>
<span class="sd">            center: The &quot;central atom&quot; of the triangle</span>
<span class="sd">            opacity: opacity of the triangle</span>
<span class="sd">            draw_edges: If set to True, the a line will be  drawn at each edge</span>
<span class="sd">            edges_color: Color of the line for the edges</span>
<span class="sd">            edges_linewidth: Width of the line drawn for the edges</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">points</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkPoints</span><span class="p">()</span>
        <span class="n">triangle</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkTriangle</span><span class="p">()</span>
        <span class="k">for</span> <span class="n">ii</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">3</span><span class="p">):</span>
            <span class="n">points</span><span class="o">.</span><span class="n">InsertNextPoint</span><span class="p">(</span><span class="n">neighbors</span><span class="p">[</span><span class="n">ii</span><span class="p">]</span><span class="o">.</span><span class="n">x</span><span class="p">,</span> <span class="n">neighbors</span><span class="p">[</span><span class="n">ii</span><span class="p">]</span><span class="o">.</span><span class="n">y</span><span class="p">,</span>
                                   <span class="n">neighbors</span><span class="p">[</span><span class="n">ii</span><span class="p">]</span><span class="o">.</span><span class="n">z</span><span class="p">)</span>
            <span class="n">triangle</span><span class="o">.</span><span class="n">GetPointIds</span><span class="p">()</span><span class="o">.</span><span class="n">SetId</span><span class="p">(</span><span class="n">ii</span><span class="p">,</span> <span class="n">ii</span><span class="p">)</span>
        <span class="n">triangles</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkCellArray</span><span class="p">()</span>
        <span class="n">triangles</span><span class="o">.</span><span class="n">InsertNextCell</span><span class="p">(</span><span class="n">triangle</span><span class="p">)</span>

        <span class="c1"># polydata object</span>
        <span class="n">trianglePolyData</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkPolyData</span><span class="p">()</span>
        <span class="n">trianglePolyData</span><span class="o">.</span><span class="n">SetPoints</span><span class="p">(</span><span class="n">points</span><span class="p">)</span>
        <span class="n">trianglePolyData</span><span class="o">.</span><span class="n">SetPolys</span><span class="p">(</span><span class="n">triangles</span><span class="p">)</span>

        <span class="c1"># mapper</span>
        <span class="n">mapper</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkPolyDataMapper</span><span class="p">()</span>
        <span class="n">mapper</span><span class="o">.</span><span class="n">SetInput</span><span class="p">(</span><span class="n">trianglePolyData</span><span class="p">)</span>

        <span class="n">ac</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkActor</span><span class="p">()</span>
        <span class="n">ac</span><span class="o">.</span><span class="n">SetMapper</span><span class="p">(</span><span class="n">mapper</span><span class="p">)</span>
        <span class="n">ac</span><span class="o">.</span><span class="n">GetProperty</span><span class="p">()</span><span class="o">.</span><span class="n">SetOpacity</span><span class="p">(</span><span class="n">opacity</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">color</span> <span class="o">==</span> <span class="s1">&#39;element&#39;</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">center</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
                <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span>
                    <span class="s1">&#39;Color should be chosen according to the central atom, &#39;</span>
                    <span class="s1">&#39;and central atom is not provided&#39;</span><span class="p">)</span>
            <span class="c1"># If partial occupations are involved, the color of the specie with</span>
            <span class="c1"># the highest occupation is used</span>
            <span class="n">myoccu</span> <span class="o">=</span> <span class="mf">0.0</span>
            <span class="k">for</span> <span class="n">specie</span><span class="p">,</span> <span class="n">occu</span> <span class="ow">in</span> <span class="n">center</span><span class="o">.</span><span class="n">species</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
                <span class="k">if</span> <span class="n">occu</span> <span class="o">&gt;</span> <span class="n">myoccu</span><span class="p">:</span>
                    <span class="n">myspecie</span> <span class="o">=</span> <span class="n">specie</span>
                    <span class="n">myoccu</span> <span class="o">=</span> <span class="n">occu</span>
            <span class="n">color</span> <span class="o">=</span> <span class="p">[</span><span class="n">i</span> <span class="o">/</span> <span class="mi">255</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">el_color_mapping</span><span class="p">[</span><span class="n">myspecie</span><span class="o">.</span><span class="n">symbol</span><span class="p">]]</span>
            <span class="n">ac</span><span class="o">.</span><span class="n">GetProperty</span><span class="p">()</span><span class="o">.</span><span class="n">SetColor</span><span class="p">(</span><span class="n">color</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">ac</span><span class="o">.</span><span class="n">GetProperty</span><span class="p">()</span><span class="o">.</span><span class="n">SetColor</span><span class="p">(</span><span class="n">color</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">draw_edges</span><span class="p">:</span>
            <span class="n">ac</span><span class="o">.</span><span class="n">GetProperty</span><span class="p">()</span><span class="o">.</span><span class="n">SetEdgeColor</span><span class="p">(</span><span class="n">edges_color</span><span class="p">)</span>
            <span class="n">ac</span><span class="o">.</span><span class="n">GetProperty</span><span class="p">()</span><span class="o">.</span><span class="n">SetLineWidth</span><span class="p">(</span><span class="n">edges_linewidth</span><span class="p">)</span>
            <span class="n">ac</span><span class="o">.</span><span class="n">GetProperty</span><span class="p">()</span><span class="o">.</span><span class="n">EdgeVisibilityOn</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">ren</span><span class="o">.</span><span class="n">AddActor</span><span class="p">(</span><span class="n">ac</span><span class="p">)</span></div>

<div class="viewcode-block" id="StructureVis.add_faces"><a class="viewcode-back" href="../../../pymatgen.vis.structure_vtk.html#pymatgen.vis.structure_vtk.StructureVis.add_faces">[docs]</a>    <span class="k">def</span> <span class="nf">add_faces</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">faces</span><span class="p">,</span> <span class="n">color</span><span class="p">,</span> <span class="n">opacity</span><span class="o">=</span><span class="mf">0.35</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Adding face of polygon.</span>

<span class="sd">        Args:</span>
<span class="sd">            faces (): Coordinates of the faces.</span>
<span class="sd">            color (): Color.</span>
<span class="sd">            opacity (float): Opacity</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">for</span> <span class="n">face</span> <span class="ow">in</span> <span class="n">faces</span><span class="p">:</span>
            <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">face</span><span class="p">)</span> <span class="o">==</span> <span class="mi">3</span><span class="p">:</span>
                <span class="n">points</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkPoints</span><span class="p">()</span>
                <span class="n">triangle</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkTriangle</span><span class="p">()</span>
                <span class="k">for</span> <span class="n">ii</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">3</span><span class="p">):</span>
                    <span class="n">points</span><span class="o">.</span><span class="n">InsertNextPoint</span><span class="p">(</span><span class="n">face</span><span class="p">[</span><span class="n">ii</span><span class="p">][</span><span class="mi">0</span><span class="p">],</span> <span class="n">face</span><span class="p">[</span><span class="n">ii</span><span class="p">][</span><span class="mi">1</span><span class="p">],</span> <span class="n">face</span><span class="p">[</span><span class="n">ii</span><span class="p">][</span><span class="mi">2</span><span class="p">])</span>
                    <span class="n">triangle</span><span class="o">.</span><span class="n">GetPointIds</span><span class="p">()</span><span class="o">.</span><span class="n">SetId</span><span class="p">(</span><span class="n">ii</span><span class="p">,</span> <span class="n">ii</span><span class="p">)</span>
                <span class="n">triangles</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkCellArray</span><span class="p">()</span>
                <span class="n">triangles</span><span class="o">.</span><span class="n">InsertNextCell</span><span class="p">(</span><span class="n">triangle</span><span class="p">)</span>
                <span class="n">trianglePolyData</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkPolyData</span><span class="p">()</span>
                <span class="n">trianglePolyData</span><span class="o">.</span><span class="n">SetPoints</span><span class="p">(</span><span class="n">points</span><span class="p">)</span>
                <span class="n">trianglePolyData</span><span class="o">.</span><span class="n">SetPolys</span><span class="p">(</span><span class="n">triangles</span><span class="p">)</span>
                <span class="n">mapper</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkPolyDataMapper</span><span class="p">()</span>
                <span class="k">if</span> <span class="n">vtk</span><span class="o">.</span><span class="n">VTK_MAJOR_VERSION</span> <span class="o">&lt;=</span> <span class="mi">5</span><span class="p">:</span>
                    <span class="n">mapper</span><span class="o">.</span><span class="n">SetInputConnection</span><span class="p">(</span><span class="n">trianglePolyData</span><span class="o">.</span><span class="n">GetProducerPort</span><span class="p">())</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="n">mapper</span><span class="o">.</span><span class="n">SetInputData</span><span class="p">(</span><span class="n">trianglePolyData</span><span class="p">)</span>
                <span class="c1"># mapper.SetInput(trianglePolyData)</span>
                <span class="n">ac</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkActor</span><span class="p">()</span>
                <span class="n">ac</span><span class="o">.</span><span class="n">SetMapper</span><span class="p">(</span><span class="n">mapper</span><span class="p">)</span>
                <span class="n">ac</span><span class="o">.</span><span class="n">GetProperty</span><span class="p">()</span><span class="o">.</span><span class="n">SetOpacity</span><span class="p">(</span><span class="n">opacity</span><span class="p">)</span>
                <span class="n">ac</span><span class="o">.</span><span class="n">GetProperty</span><span class="p">()</span><span class="o">.</span><span class="n">SetColor</span><span class="p">(</span><span class="n">color</span><span class="p">)</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">ren</span><span class="o">.</span><span class="n">AddActor</span><span class="p">(</span><span class="n">ac</span><span class="p">)</span>
            <span class="k">elif</span> <span class="kc">False</span> <span class="ow">and</span> <span class="nb">len</span><span class="p">(</span><span class="n">face</span><span class="p">)</span> <span class="o">==</span> <span class="mi">4</span><span class="p">:</span>
                <span class="n">points</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkPoints</span><span class="p">()</span>
                <span class="k">for</span> <span class="n">ii</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">4</span><span class="p">):</span>
                    <span class="n">points</span><span class="o">.</span><span class="n">InsertNextPoint</span><span class="p">(</span><span class="n">face</span><span class="p">[</span><span class="n">ii</span><span class="p">][</span><span class="mi">0</span><span class="p">],</span> <span class="n">face</span><span class="p">[</span><span class="n">ii</span><span class="p">][</span><span class="mi">1</span><span class="p">],</span> <span class="n">face</span><span class="p">[</span><span class="n">ii</span><span class="p">][</span><span class="mi">2</span><span class="p">])</span>
                <span class="n">line1</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkLine</span><span class="p">()</span>
                <span class="n">line1</span><span class="o">.</span><span class="n">GetPointIds</span><span class="p">()</span><span class="o">.</span><span class="n">SetId</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span>
                <span class="n">line1</span><span class="o">.</span><span class="n">GetPointIds</span><span class="p">()</span><span class="o">.</span><span class="n">SetId</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">)</span>
                <span class="n">line2</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkLine</span><span class="p">()</span>
                <span class="n">line2</span><span class="o">.</span><span class="n">GetPointIds</span><span class="p">()</span><span class="o">.</span><span class="n">SetId</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">3</span><span class="p">)</span>
                <span class="n">line2</span><span class="o">.</span><span class="n">GetPointIds</span><span class="p">()</span><span class="o">.</span><span class="n">SetId</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
                <span class="n">lines</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkCellArray</span><span class="p">()</span>
                <span class="n">lines</span><span class="o">.</span><span class="n">InsertNextCell</span><span class="p">(</span><span class="n">line1</span><span class="p">)</span>
                <span class="n">lines</span><span class="o">.</span><span class="n">InsertNextCell</span><span class="p">(</span><span class="n">line2</span><span class="p">)</span>
                <span class="n">polydata</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkPolyData</span><span class="p">()</span>
                <span class="n">polydata</span><span class="o">.</span><span class="n">SetPoints</span><span class="p">(</span><span class="n">points</span><span class="p">)</span>
                <span class="n">polydata</span><span class="o">.</span><span class="n">SetLines</span><span class="p">(</span><span class="n">lines</span><span class="p">)</span>
                <span class="n">ruledSurfaceFilter</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkRuledSurfaceFilter</span><span class="p">()</span>
                <span class="n">ruledSurfaceFilter</span><span class="o">.</span><span class="n">SetInput</span><span class="p">(</span><span class="n">polydata</span><span class="p">)</span>
                <span class="n">ruledSurfaceFilter</span><span class="o">.</span><span class="n">SetResolution</span><span class="p">(</span><span class="mi">15</span><span class="p">,</span> <span class="mi">15</span><span class="p">)</span>
                <span class="n">ruledSurfaceFilter</span><span class="o">.</span><span class="n">SetRuledModeToResample</span><span class="p">()</span>
                <span class="n">mapper</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkPolyDataMapper</span><span class="p">()</span>
                <span class="n">mapper</span><span class="o">.</span><span class="n">SetInput</span><span class="p">(</span><span class="n">ruledSurfaceFilter</span><span class="o">.</span><span class="n">GetOutput</span><span class="p">())</span>
                <span class="n">ac</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkActor</span><span class="p">()</span>
                <span class="n">ac</span><span class="o">.</span><span class="n">SetMapper</span><span class="p">(</span><span class="n">mapper</span><span class="p">)</span>
                <span class="n">ac</span><span class="o">.</span><span class="n">GetProperty</span><span class="p">()</span><span class="o">.</span><span class="n">SetOpacity</span><span class="p">(</span><span class="n">opacity</span><span class="p">)</span>
                <span class="n">ac</span><span class="o">.</span><span class="n">GetProperty</span><span class="p">()</span><span class="o">.</span><span class="n">SetColor</span><span class="p">(</span><span class="n">color</span><span class="p">)</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">ren</span><span class="o">.</span><span class="n">AddActor</span><span class="p">(</span><span class="n">ac</span><span class="p">)</span>
            <span class="k">elif</span> <span class="nb">len</span><span class="p">(</span><span class="n">face</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">3</span><span class="p">:</span>
                <span class="n">center</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="mi">3</span><span class="p">,</span> <span class="n">np</span><span class="o">.</span><span class="n">float</span><span class="p">)</span>
                <span class="k">for</span> <span class="n">site</span> <span class="ow">in</span> <span class="n">face</span><span class="p">:</span>
                    <span class="n">center</span> <span class="o">+=</span> <span class="n">site</span>
                <span class="n">center</span> <span class="o">/=</span> <span class="n">np</span><span class="o">.</span><span class="n">float</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">face</span><span class="p">))</span>
                <span class="k">for</span> <span class="n">ii</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">face</span><span class="p">)):</span>
                    <span class="n">points</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkPoints</span><span class="p">()</span>
                    <span class="n">triangle</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkTriangle</span><span class="p">()</span>
                    <span class="n">points</span><span class="o">.</span><span class="n">InsertNextPoint</span><span class="p">(</span><span class="n">face</span><span class="p">[</span><span class="n">ii</span><span class="p">][</span><span class="mi">0</span><span class="p">],</span> <span class="n">face</span><span class="p">[</span><span class="n">ii</span><span class="p">][</span><span class="mi">1</span><span class="p">],</span> <span class="n">face</span><span class="p">[</span><span class="n">ii</span><span class="p">][</span><span class="mi">2</span><span class="p">])</span>
                    <span class="n">ii2</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">mod</span><span class="p">(</span><span class="n">ii</span> <span class="o">+</span> <span class="mi">1</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="n">face</span><span class="p">))</span>
                    <span class="n">points</span><span class="o">.</span><span class="n">InsertNextPoint</span><span class="p">(</span><span class="n">face</span><span class="p">[</span><span class="n">ii2</span><span class="p">][</span><span class="mi">0</span><span class="p">],</span> <span class="n">face</span><span class="p">[</span><span class="n">ii2</span><span class="p">][</span><span class="mi">1</span><span class="p">],</span> <span class="n">face</span><span class="p">[</span><span class="n">ii2</span><span class="p">][</span><span class="mi">2</span><span class="p">])</span>
                    <span class="n">points</span><span class="o">.</span><span class="n">InsertNextPoint</span><span class="p">(</span><span class="n">center</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">center</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="n">center</span><span class="p">[</span><span class="mi">2</span><span class="p">])</span>
                    <span class="k">for</span> <span class="n">ii</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">3</span><span class="p">):</span>
                        <span class="n">triangle</span><span class="o">.</span><span class="n">GetPointIds</span><span class="p">()</span><span class="o">.</span><span class="n">SetId</span><span class="p">(</span><span class="n">ii</span><span class="p">,</span> <span class="n">ii</span><span class="p">)</span>
                    <span class="n">triangles</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkCellArray</span><span class="p">()</span>
                    <span class="n">triangles</span><span class="o">.</span><span class="n">InsertNextCell</span><span class="p">(</span><span class="n">triangle</span><span class="p">)</span>
                    <span class="n">trianglePolyData</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkPolyData</span><span class="p">()</span>
                    <span class="n">trianglePolyData</span><span class="o">.</span><span class="n">SetPoints</span><span class="p">(</span><span class="n">points</span><span class="p">)</span>
                    <span class="n">trianglePolyData</span><span class="o">.</span><span class="n">SetPolys</span><span class="p">(</span><span class="n">triangles</span><span class="p">)</span>
                    <span class="n">mapper</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkPolyDataMapper</span><span class="p">()</span>
                    <span class="k">if</span> <span class="n">vtk</span><span class="o">.</span><span class="n">VTK_MAJOR_VERSION</span> <span class="o">&lt;=</span> <span class="mi">5</span><span class="p">:</span>
                        <span class="n">mapper</span><span class="o">.</span><span class="n">SetInputConnection</span><span class="p">(</span><span class="n">trianglePolyData</span><span class="o">.</span><span class="n">GetProducerPort</span><span class="p">())</span>
                    <span class="k">else</span><span class="p">:</span>
                        <span class="n">mapper</span><span class="o">.</span><span class="n">SetInputData</span><span class="p">(</span><span class="n">trianglePolyData</span><span class="p">)</span>
                    <span class="c1"># mapper.SetInput(trianglePolyData)</span>
                    <span class="n">ac</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkActor</span><span class="p">()</span>
                    <span class="n">ac</span><span class="o">.</span><span class="n">SetMapper</span><span class="p">(</span><span class="n">mapper</span><span class="p">)</span>
                    <span class="n">ac</span><span class="o">.</span><span class="n">GetProperty</span><span class="p">()</span><span class="o">.</span><span class="n">SetOpacity</span><span class="p">(</span><span class="n">opacity</span><span class="p">)</span>
                    <span class="n">ac</span><span class="o">.</span><span class="n">GetProperty</span><span class="p">()</span><span class="o">.</span><span class="n">SetColor</span><span class="p">(</span><span class="n">color</span><span class="p">)</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">ren</span><span class="o">.</span><span class="n">AddActor</span><span class="p">(</span><span class="n">ac</span><span class="p">)</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;Number of points for a face should be &gt;= 3&quot;</span><span class="p">)</span></div>

<div class="viewcode-block" id="StructureVis.add_edges"><a class="viewcode-back" href="../../../pymatgen.vis.structure_vtk.html#pymatgen.vis.structure_vtk.StructureVis.add_edges">[docs]</a>    <span class="k">def</span> <span class="nf">add_edges</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">edges</span><span class="p">,</span> <span class="nb">type</span><span class="o">=</span><span class="s1">&#39;line&#39;</span><span class="p">,</span> <span class="n">linewidth</span><span class="o">=</span><span class="mi">2</span><span class="p">,</span> <span class="n">color</span><span class="o">=</span><span class="p">[</span><span class="mf">0.0</span><span class="p">,</span> <span class="mf">0.0</span><span class="p">,</span> <span class="mf">0.0</span><span class="p">]):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Args:</span>
<span class="sd">            edges (): List of edges</span>
<span class="sd">            type ():</span>
<span class="sd">            linewidth (): Width of line</span>
<span class="sd">            color (nd.array/tuple): RGB color.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">points</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkPoints</span><span class="p">()</span>
        <span class="n">lines</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkCellArray</span><span class="p">()</span>
        <span class="k">for</span> <span class="n">iedge</span><span class="p">,</span> <span class="n">edge</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">edges</span><span class="p">):</span>
            <span class="n">points</span><span class="o">.</span><span class="n">InsertPoint</span><span class="p">(</span><span class="mi">2</span> <span class="o">*</span> <span class="n">iedge</span><span class="p">,</span> <span class="n">edge</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
            <span class="n">points</span><span class="o">.</span><span class="n">InsertPoint</span><span class="p">(</span><span class="mi">2</span> <span class="o">*</span> <span class="n">iedge</span> <span class="o">+</span> <span class="mi">1</span><span class="p">,</span> <span class="n">edge</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span>
            <span class="n">lines</span><span class="o">.</span><span class="n">InsertNextCell</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span>
            <span class="n">lines</span><span class="o">.</span><span class="n">InsertCellPoint</span><span class="p">(</span><span class="mi">2</span> <span class="o">*</span> <span class="n">iedge</span><span class="p">)</span>
            <span class="n">lines</span><span class="o">.</span><span class="n">InsertCellPoint</span><span class="p">(</span><span class="mi">2</span> <span class="o">*</span> <span class="n">iedge</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span>
        <span class="n">polydata</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkPolyData</span><span class="p">()</span>
        <span class="n">polydata</span><span class="o">.</span><span class="n">SetPoints</span><span class="p">(</span><span class="n">points</span><span class="p">)</span>
        <span class="n">polydata</span><span class="o">.</span><span class="n">SetLines</span><span class="p">(</span><span class="n">lines</span><span class="p">)</span>
        <span class="n">mapper</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkPolyDataMapper</span><span class="p">()</span>
        <span class="k">if</span> <span class="n">vtk</span><span class="o">.</span><span class="n">VTK_MAJOR_VERSION</span> <span class="o">&lt;=</span> <span class="mi">5</span><span class="p">:</span>
            <span class="n">mapper</span><span class="o">.</span><span class="n">SetInputConnection</span><span class="p">(</span><span class="n">polydata</span><span class="o">.</span><span class="n">GetProducerPort</span><span class="p">())</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">mapper</span><span class="o">.</span><span class="n">SetInputData</span><span class="p">(</span><span class="n">polydata</span><span class="p">)</span>
        <span class="c1"># mapper.SetInput(polydata)</span>
        <span class="n">ac</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkActor</span><span class="p">()</span>
        <span class="n">ac</span><span class="o">.</span><span class="n">SetMapper</span><span class="p">(</span><span class="n">mapper</span><span class="p">)</span>
        <span class="n">ac</span><span class="o">.</span><span class="n">GetProperty</span><span class="p">()</span><span class="o">.</span><span class="n">SetColor</span><span class="p">(</span><span class="n">color</span><span class="p">)</span>
        <span class="n">ac</span><span class="o">.</span><span class="n">GetProperty</span><span class="p">()</span><span class="o">.</span><span class="n">SetLineWidth</span><span class="p">(</span><span class="n">linewidth</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">ren</span><span class="o">.</span><span class="n">AddActor</span><span class="p">(</span><span class="n">ac</span><span class="p">)</span></div>

<div class="viewcode-block" id="StructureVis.add_bonds"><a class="viewcode-back" href="../../../pymatgen.vis.structure_vtk.html#pymatgen.vis.structure_vtk.StructureVis.add_bonds">[docs]</a>    <span class="k">def</span> <span class="nf">add_bonds</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">neighbors</span><span class="p">,</span> <span class="n">center</span><span class="p">,</span> <span class="n">color</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">opacity</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
                  <span class="n">radius</span><span class="o">=</span><span class="mf">0.1</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Adds bonds for a site.</span>

<span class="sd">        Args:</span>
<span class="sd">            neighbors: Neighbors of the site.</span>
<span class="sd">            center: The site in the center for all bonds.</span>
<span class="sd">            color: Color of the tubes representing the bonds</span>
<span class="sd">            opacity: Opacity of the tubes representing the bonds</span>
<span class="sd">            radius: Radius of tube s representing the bonds</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">points</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkPoints</span><span class="p">()</span>
        <span class="n">points</span><span class="o">.</span><span class="n">InsertPoint</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="n">center</span><span class="o">.</span><span class="n">x</span><span class="p">,</span> <span class="n">center</span><span class="o">.</span><span class="n">y</span><span class="p">,</span> <span class="n">center</span><span class="o">.</span><span class="n">z</span><span class="p">)</span>
        <span class="n">n</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">neighbors</span><span class="p">)</span>
        <span class="n">lines</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkCellArray</span><span class="p">()</span>
        <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">n</span><span class="p">):</span>
            <span class="n">points</span><span class="o">.</span><span class="n">InsertPoint</span><span class="p">(</span><span class="n">i</span> <span class="o">+</span> <span class="mi">1</span><span class="p">,</span> <span class="n">neighbors</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">coords</span><span class="p">)</span>
            <span class="n">lines</span><span class="o">.</span><span class="n">InsertNextCell</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span>
            <span class="n">lines</span><span class="o">.</span><span class="n">InsertCellPoint</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span>
            <span class="n">lines</span><span class="o">.</span><span class="n">InsertCellPoint</span><span class="p">(</span><span class="n">i</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span>
        <span class="n">pd</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkPolyData</span><span class="p">()</span>
        <span class="n">pd</span><span class="o">.</span><span class="n">SetPoints</span><span class="p">(</span><span class="n">points</span><span class="p">)</span>
        <span class="n">pd</span><span class="o">.</span><span class="n">SetLines</span><span class="p">(</span><span class="n">lines</span><span class="p">)</span>

        <span class="n">tube</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkTubeFilter</span><span class="p">()</span>
        <span class="k">if</span> <span class="n">vtk</span><span class="o">.</span><span class="n">VTK_MAJOR_VERSION</span> <span class="o">&lt;=</span> <span class="mi">5</span><span class="p">:</span>
            <span class="n">tube</span><span class="o">.</span><span class="n">SetInputConnection</span><span class="p">(</span><span class="n">pd</span><span class="o">.</span><span class="n">GetProducerPort</span><span class="p">())</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">tube</span><span class="o">.</span><span class="n">SetInputData</span><span class="p">(</span><span class="n">pd</span><span class="p">)</span>
        <span class="n">tube</span><span class="o">.</span><span class="n">SetRadius</span><span class="p">(</span><span class="n">radius</span><span class="p">)</span>

        <span class="n">mapper</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkPolyDataMapper</span><span class="p">()</span>
        <span class="n">mapper</span><span class="o">.</span><span class="n">SetInputConnection</span><span class="p">(</span><span class="n">tube</span><span class="o">.</span><span class="n">GetOutputPort</span><span class="p">())</span>

        <span class="n">actor</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkActor</span><span class="p">()</span>
        <span class="n">actor</span><span class="o">.</span><span class="n">SetMapper</span><span class="p">(</span><span class="n">mapper</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">opacity</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
            <span class="n">actor</span><span class="o">.</span><span class="n">GetProperty</span><span class="p">()</span><span class="o">.</span><span class="n">SetOpacity</span><span class="p">(</span><span class="n">opacity</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">color</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
            <span class="n">actor</span><span class="o">.</span><span class="n">GetProperty</span><span class="p">()</span><span class="o">.</span><span class="n">SetColor</span><span class="p">(</span><span class="n">color</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">ren</span><span class="o">.</span><span class="n">AddActor</span><span class="p">(</span><span class="n">actor</span><span class="p">)</span></div>

<div class="viewcode-block" id="StructureVis.add_picker_fixed"><a class="viewcode-back" href="../../../pymatgen.vis.structure_vtk.html#pymatgen.vis.structure_vtk.StructureVis.add_picker_fixed">[docs]</a>    <span class="k">def</span> <span class="nf">add_picker_fixed</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Create a cell picker.Returns:</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">picker</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkCellPicker</span><span class="p">()</span>

        <span class="c1"># Create a Python function to create the text for the text mapper used</span>
        <span class="c1"># to display the results of picking.</span>

        <span class="k">def</span> <span class="nf">annotate_pick</span><span class="p">(</span><span class="n">obj</span><span class="p">,</span> <span class="n">event</span><span class="p">):</span>
            <span class="k">if</span> <span class="n">picker</span><span class="o">.</span><span class="n">GetCellId</span><span class="p">()</span> <span class="o">&lt;</span> <span class="mi">0</span> <span class="ow">and</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">show_help</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">helptxt_actor</span><span class="o">.</span><span class="n">VisibilityOff</span><span class="p">()</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">mapper</span> <span class="o">=</span> <span class="n">picker</span><span class="o">.</span><span class="n">GetMapper</span><span class="p">()</span>
                <span class="k">if</span> <span class="n">mapper</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">mapper_map</span><span class="p">:</span>
                    <span class="n">output</span> <span class="o">=</span> <span class="p">[]</span>
                    <span class="k">for</span> <span class="n">site</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">mapper_map</span><span class="p">[</span><span class="n">mapper</span><span class="p">]:</span>
                        <span class="n">row</span> <span class="o">=</span> <span class="p">[</span><span class="s2">&quot;</span><span class="si">{}</span><span class="s2"> - &quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">site</span><span class="o">.</span><span class="n">species_string</span><span class="p">),</span>
                               <span class="s2">&quot;, &quot;</span><span class="o">.</span><span class="n">join</span><span class="p">([</span><span class="s2">&quot;</span><span class="si">{:.3f}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">c</span><span class="p">)</span>
                                          <span class="k">for</span> <span class="n">c</span> <span class="ow">in</span> <span class="n">site</span><span class="o">.</span><span class="n">frac_coords</span><span class="p">]),</span>
                               <span class="s2">&quot;[&quot;</span> <span class="o">+</span> <span class="s2">&quot;, &quot;</span><span class="o">.</span><span class="n">join</span><span class="p">([</span><span class="s2">&quot;</span><span class="si">{:.3f}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">c</span><span class="p">)</span>
                                                <span class="k">for</span> <span class="n">c</span> <span class="ow">in</span> <span class="n">site</span><span class="o">.</span><span class="n">coords</span><span class="p">])</span> <span class="o">+</span>
                               <span class="s2">&quot;]&quot;</span><span class="p">]</span>
                        <span class="n">output</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s2">&quot;&quot;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">row</span><span class="p">))</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">helptxt_mapper</span><span class="o">.</span><span class="n">SetInput</span><span class="p">(</span><span class="s2">&quot;</span><span class="se">\n</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">output</span><span class="p">))</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">helptxt_actor</span><span class="o">.</span><span class="n">SetPosition</span><span class="p">(</span><span class="mi">10</span><span class="p">,</span> <span class="mi">10</span><span class="p">)</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">helptxt_actor</span><span class="o">.</span><span class="n">VisibilityOn</span><span class="p">()</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">show_help</span> <span class="o">=</span> <span class="kc">False</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">picker</span> <span class="o">=</span> <span class="n">picker</span>
        <span class="n">picker</span><span class="o">.</span><span class="n">AddObserver</span><span class="p">(</span><span class="s2">&quot;EndPickEvent&quot;</span><span class="p">,</span> <span class="n">annotate_pick</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">iren</span><span class="o">.</span><span class="n">SetPicker</span><span class="p">(</span><span class="n">picker</span><span class="p">)</span></div>

<div class="viewcode-block" id="StructureVis.add_picker"><a class="viewcode-back" href="../../../pymatgen.vis.structure_vtk.html#pymatgen.vis.structure_vtk.StructureVis.add_picker">[docs]</a>    <span class="k">def</span> <span class="nf">add_picker</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Create a cell picker.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">picker</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkCellPicker</span><span class="p">()</span>
        <span class="c1"># Create a Python function to create the text for the text mapper used</span>
        <span class="c1"># to display the results of picking.</span>
        <span class="n">source</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkVectorText</span><span class="p">()</span>
        <span class="n">mapper</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkPolyDataMapper</span><span class="p">()</span>
        <span class="n">mapper</span><span class="o">.</span><span class="n">SetInputConnection</span><span class="p">(</span><span class="n">source</span><span class="o">.</span><span class="n">GetOutputPort</span><span class="p">())</span>
        <span class="n">follower</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkFollower</span><span class="p">()</span>
        <span class="n">follower</span><span class="o">.</span><span class="n">SetMapper</span><span class="p">(</span><span class="n">mapper</span><span class="p">)</span>
        <span class="n">follower</span><span class="o">.</span><span class="n">GetProperty</span><span class="p">()</span><span class="o">.</span><span class="n">SetColor</span><span class="p">((</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">))</span>
        <span class="n">follower</span><span class="o">.</span><span class="n">SetScale</span><span class="p">(</span><span class="mf">0.2</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">ren</span><span class="o">.</span><span class="n">AddActor</span><span class="p">(</span><span class="n">follower</span><span class="p">)</span>
        <span class="n">follower</span><span class="o">.</span><span class="n">SetCamera</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">ren</span><span class="o">.</span><span class="n">GetActiveCamera</span><span class="p">())</span>
        <span class="n">follower</span><span class="o">.</span><span class="n">VisibilityOff</span><span class="p">()</span>

        <span class="k">def</span> <span class="nf">annotate_pick</span><span class="p">(</span><span class="n">obj</span><span class="p">,</span> <span class="n">event</span><span class="p">):</span>
            <span class="k">if</span> <span class="n">picker</span><span class="o">.</span><span class="n">GetCellId</span><span class="p">()</span> <span class="o">&lt;</span> <span class="mi">0</span><span class="p">:</span>
                <span class="n">follower</span><span class="o">.</span><span class="n">VisibilityOff</span><span class="p">()</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">pick_pos</span> <span class="o">=</span> <span class="n">picker</span><span class="o">.</span><span class="n">GetPickPosition</span><span class="p">()</span>
                <span class="n">mapper</span> <span class="o">=</span> <span class="n">picker</span><span class="o">.</span><span class="n">GetMapper</span><span class="p">()</span>
                <span class="k">if</span> <span class="n">mapper</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">mapper_map</span><span class="p">:</span>
                    <span class="n">site</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">mapper_map</span><span class="p">[</span><span class="n">mapper</span><span class="p">]</span>
                    <span class="n">output</span> <span class="o">=</span> <span class="p">[</span><span class="n">site</span><span class="o">.</span><span class="n">species_string</span><span class="p">,</span> <span class="s2">&quot;Frac. coords: &quot;</span> <span class="o">+</span>
                              <span class="s2">&quot; &quot;</span><span class="o">.</span><span class="n">join</span><span class="p">([</span><span class="s2">&quot;</span><span class="si">{:.4f}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">c</span><span class="p">)</span>
                                        <span class="k">for</span> <span class="n">c</span> <span class="ow">in</span>
                                        <span class="n">site</span><span class="o">.</span><span class="n">frac_coords</span><span class="p">])]</span>
                    <span class="n">source</span><span class="o">.</span><span class="n">SetText</span><span class="p">(</span><span class="s2">&quot;</span><span class="se">\n</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">output</span><span class="p">))</span>
                    <span class="n">follower</span><span class="o">.</span><span class="n">SetPosition</span><span class="p">(</span><span class="n">pick_pos</span><span class="p">)</span>
                    <span class="n">follower</span><span class="o">.</span><span class="n">VisibilityOn</span><span class="p">()</span>

        <span class="n">picker</span><span class="o">.</span><span class="n">AddObserver</span><span class="p">(</span><span class="s2">&quot;EndPickEvent&quot;</span><span class="p">,</span> <span class="n">annotate_pick</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">picker</span> <span class="o">=</span> <span class="n">picker</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">iren</span><span class="o">.</span><span class="n">SetPicker</span><span class="p">(</span><span class="n">picker</span><span class="p">)</span></div></div>


<div class="viewcode-block" id="StructureInteractorStyle"><a class="viewcode-back" href="../../../pymatgen.vis.structure_vtk.html#pymatgen.vis.structure_vtk.StructureInteractorStyle">[docs]</a><span class="k">class</span> <span class="nc">StructureInteractorStyle</span><span class="p">(</span><span class="n">vtkInteractorStyleTrackballCamera</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    A custom interactor style for visualizing structures.</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">parent</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Args:</span>
<span class="sd">            parent ():</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">parent</span> <span class="o">=</span> <span class="n">parent</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">AddObserver</span><span class="p">(</span><span class="s2">&quot;LeftButtonPressEvent&quot;</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">leftButtonPressEvent</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">AddObserver</span><span class="p">(</span><span class="s2">&quot;MouseMoveEvent&quot;</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">mouseMoveEvent</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">AddObserver</span><span class="p">(</span><span class="s2">&quot;LeftButtonReleaseEvent&quot;</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">leftButtonReleaseEvent</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">AddObserver</span><span class="p">(</span><span class="s2">&quot;KeyPressEvent&quot;</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">keyPressEvent</span><span class="p">)</span>

<div class="viewcode-block" id="StructureInteractorStyle.leftButtonPressEvent"><a class="viewcode-back" href="../../../pymatgen.vis.structure_vtk.html#pymatgen.vis.structure_vtk.StructureInteractorStyle.leftButtonPressEvent">[docs]</a>    <span class="k">def</span> <span class="nf">leftButtonPressEvent</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">obj</span><span class="p">,</span> <span class="n">event</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Args:</span>
<span class="sd">            obj ():</span>
<span class="sd">            event ():</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">mouse_motion</span> <span class="o">=</span> <span class="mi">0</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">OnLeftButtonDown</span><span class="p">()</span>
        <span class="k">return</span></div>

<div class="viewcode-block" id="StructureInteractorStyle.mouseMoveEvent"><a class="viewcode-back" href="../../../pymatgen.vis.structure_vtk.html#pymatgen.vis.structure_vtk.StructureInteractorStyle.mouseMoveEvent">[docs]</a>    <span class="k">def</span> <span class="nf">mouseMoveEvent</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">obj</span><span class="p">,</span> <span class="n">event</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Args:</span>
<span class="sd">            obj ():</span>
<span class="sd">            event ():</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">mouse_motion</span> <span class="o">=</span> <span class="mi">1</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">OnMouseMove</span><span class="p">()</span>
        <span class="k">return</span></div>

<div class="viewcode-block" id="StructureInteractorStyle.leftButtonReleaseEvent"><a class="viewcode-back" href="../../../pymatgen.vis.structure_vtk.html#pymatgen.vis.structure_vtk.StructureInteractorStyle.leftButtonReleaseEvent">[docs]</a>    <span class="k">def</span> <span class="nf">leftButtonReleaseEvent</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">obj</span><span class="p">,</span> <span class="n">event</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Args:</span>
<span class="sd">            obj ():</span>
<span class="sd">            event ():</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">ren</span> <span class="o">=</span> <span class="n">obj</span><span class="o">.</span><span class="n">GetCurrentRenderer</span><span class="p">()</span>
        <span class="n">iren</span> <span class="o">=</span> <span class="n">ren</span><span class="o">.</span><span class="n">GetRenderWindow</span><span class="p">()</span><span class="o">.</span><span class="n">GetInteractor</span><span class="p">()</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">mouse_motion</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
            <span class="n">pos</span> <span class="o">=</span> <span class="n">iren</span><span class="o">.</span><span class="n">GetEventPosition</span><span class="p">()</span>
            <span class="n">iren</span><span class="o">.</span><span class="n">GetPicker</span><span class="p">()</span><span class="o">.</span><span class="n">Pick</span><span class="p">(</span><span class="n">pos</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">pos</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="mi">0</span><span class="p">,</span> <span class="n">ren</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">OnLeftButtonUp</span><span class="p">()</span>
        <span class="k">return</span></div>

<div class="viewcode-block" id="StructureInteractorStyle.keyPressEvent"><a class="viewcode-back" href="../../../pymatgen.vis.structure_vtk.html#pymatgen.vis.structure_vtk.StructureInteractorStyle.keyPressEvent">[docs]</a>    <span class="k">def</span> <span class="nf">keyPressEvent</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">obj</span><span class="p">,</span> <span class="n">event</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Args:</span>
<span class="sd">            obj ():</span>
<span class="sd">            event ():</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">parent</span> <span class="o">=</span> <span class="n">obj</span><span class="o">.</span><span class="n">GetCurrentRenderer</span><span class="p">()</span><span class="o">.</span><span class="n">parent</span>
        <span class="n">sym</span> <span class="o">=</span> <span class="n">parent</span><span class="o">.</span><span class="n">iren</span><span class="o">.</span><span class="n">GetKeySym</span><span class="p">()</span>

        <span class="k">if</span> <span class="n">sym</span> <span class="ow">in</span> <span class="s2">&quot;ABCabc&quot;</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">sym</span> <span class="o">==</span> <span class="s2">&quot;A&quot;</span><span class="p">:</span>
                <span class="n">parent</span><span class="o">.</span><span class="n">supercell</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span> <span class="o">+=</span> <span class="mi">1</span>
            <span class="k">elif</span> <span class="n">sym</span> <span class="o">==</span> <span class="s2">&quot;B&quot;</span><span class="p">:</span>
                <span class="n">parent</span><span class="o">.</span><span class="n">supercell</span><span class="p">[</span><span class="mi">1</span><span class="p">][</span><span class="mi">1</span><span class="p">]</span> <span class="o">+=</span> <span class="mi">1</span>
            <span class="k">elif</span> <span class="n">sym</span> <span class="o">==</span> <span class="s2">&quot;C&quot;</span><span class="p">:</span>
                <span class="n">parent</span><span class="o">.</span><span class="n">supercell</span><span class="p">[</span><span class="mi">2</span><span class="p">][</span><span class="mi">2</span><span class="p">]</span> <span class="o">+=</span> <span class="mi">1</span>
            <span class="k">elif</span> <span class="n">sym</span> <span class="o">==</span> <span class="s2">&quot;a&quot;</span><span class="p">:</span>
                <span class="n">parent</span><span class="o">.</span><span class="n">supercell</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="nb">max</span><span class="p">(</span><span class="n">parent</span><span class="o">.</span><span class="n">supercell</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span> <span class="o">-</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
            <span class="k">elif</span> <span class="n">sym</span> <span class="o">==</span> <span class="s2">&quot;b&quot;</span><span class="p">:</span>
                <span class="n">parent</span><span class="o">.</span><span class="n">supercell</span><span class="p">[</span><span class="mi">1</span><span class="p">][</span><span class="mi">1</span><span class="p">]</span> <span class="o">=</span> <span class="nb">max</span><span class="p">(</span><span class="n">parent</span><span class="o">.</span><span class="n">supercell</span><span class="p">[</span><span class="mi">1</span><span class="p">][</span><span class="mi">1</span><span class="p">]</span> <span class="o">-</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
            <span class="k">elif</span> <span class="n">sym</span> <span class="o">==</span> <span class="s2">&quot;c&quot;</span><span class="p">:</span>
                <span class="n">parent</span><span class="o">.</span><span class="n">supercell</span><span class="p">[</span><span class="mi">2</span><span class="p">][</span><span class="mi">2</span><span class="p">]</span> <span class="o">=</span> <span class="nb">max</span><span class="p">(</span><span class="n">parent</span><span class="o">.</span><span class="n">supercell</span><span class="p">[</span><span class="mi">2</span><span class="p">][</span><span class="mi">2</span><span class="p">]</span> <span class="o">-</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
            <span class="n">parent</span><span class="o">.</span><span class="n">redraw</span><span class="p">()</span>
        <span class="k">elif</span> <span class="n">sym</span> <span class="o">==</span> <span class="s2">&quot;numbersign&quot;</span><span class="p">:</span>
            <span class="n">parent</span><span class="o">.</span><span class="n">show_polyhedron</span> <span class="o">=</span> <span class="ow">not</span> <span class="n">parent</span><span class="o">.</span><span class="n">show_polyhedron</span>
            <span class="n">parent</span><span class="o">.</span><span class="n">redraw</span><span class="p">()</span>
        <span class="k">elif</span> <span class="n">sym</span> <span class="o">==</span> <span class="s2">&quot;minus&quot;</span><span class="p">:</span>
            <span class="n">parent</span><span class="o">.</span><span class="n">show_bonds</span> <span class="o">=</span> <span class="ow">not</span> <span class="n">parent</span><span class="o">.</span><span class="n">show_bonds</span>
            <span class="n">parent</span><span class="o">.</span><span class="n">redraw</span><span class="p">()</span>
        <span class="k">elif</span> <span class="n">sym</span> <span class="o">==</span> <span class="s2">&quot;bracketleft&quot;</span><span class="p">:</span>
            <span class="n">parent</span><span class="o">.</span><span class="n">poly_radii_tol_factor</span> <span class="o">-=</span> <span class="mf">0.05</span> \
                <span class="k">if</span> <span class="n">parent</span><span class="o">.</span><span class="n">poly_radii_tol_factor</span> <span class="o">&gt;</span> <span class="mi">0</span> <span class="k">else</span> <span class="mi">0</span>
            <span class="n">parent</span><span class="o">.</span><span class="n">redraw</span><span class="p">()</span>
        <span class="k">elif</span> <span class="n">sym</span> <span class="o">==</span> <span class="s2">&quot;bracketright&quot;</span><span class="p">:</span>
            <span class="n">parent</span><span class="o">.</span><span class="n">poly_radii_tol_factor</span> <span class="o">+=</span> <span class="mf">0.05</span>
            <span class="n">parent</span><span class="o">.</span><span class="n">redraw</span><span class="p">()</span>
        <span class="k">elif</span> <span class="n">sym</span> <span class="o">==</span> <span class="s2">&quot;h&quot;</span><span class="p">:</span>
            <span class="n">parent</span><span class="o">.</span><span class="n">show_help</span> <span class="o">=</span> <span class="ow">not</span> <span class="n">parent</span><span class="o">.</span><span class="n">show_help</span>
            <span class="n">parent</span><span class="o">.</span><span class="n">redraw</span><span class="p">()</span>
        <span class="k">elif</span> <span class="n">sym</span> <span class="o">==</span> <span class="s2">&quot;r&quot;</span><span class="p">:</span>
            <span class="n">parent</span><span class="o">.</span><span class="n">redraw</span><span class="p">(</span><span class="kc">True</span><span class="p">)</span>
        <span class="k">elif</span> <span class="n">sym</span> <span class="o">==</span> <span class="s2">&quot;s&quot;</span><span class="p">:</span>
            <span class="n">parent</span><span class="o">.</span><span class="n">write_image</span><span class="p">(</span><span class="s2">&quot;image.png&quot;</span><span class="p">)</span>
        <span class="k">elif</span> <span class="n">sym</span> <span class="o">==</span> <span class="s2">&quot;Up&quot;</span><span class="p">:</span>
            <span class="n">parent</span><span class="o">.</span><span class="n">rotate_view</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">90</span><span class="p">)</span>
        <span class="k">elif</span> <span class="n">sym</span> <span class="o">==</span> <span class="s2">&quot;Down&quot;</span><span class="p">:</span>
            <span class="n">parent</span><span class="o">.</span><span class="n">rotate_view</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="o">-</span><span class="mi">90</span><span class="p">)</span>
        <span class="k">elif</span> <span class="n">sym</span> <span class="o">==</span> <span class="s2">&quot;Left&quot;</span><span class="p">:</span>
            <span class="n">parent</span><span class="o">.</span><span class="n">rotate_view</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="o">-</span><span class="mi">90</span><span class="p">)</span>
        <span class="k">elif</span> <span class="n">sym</span> <span class="o">==</span> <span class="s2">&quot;Right&quot;</span><span class="p">:</span>
            <span class="n">parent</span><span class="o">.</span><span class="n">rotate_view</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">90</span><span class="p">)</span>
        <span class="k">elif</span> <span class="n">sym</span> <span class="o">==</span> <span class="s2">&quot;o&quot;</span><span class="p">:</span>
            <span class="n">parent</span><span class="o">.</span><span class="n">orthongonalize_structure</span><span class="p">()</span>
            <span class="n">parent</span><span class="o">.</span><span class="n">redraw</span><span class="p">()</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">OnKeyPress</span><span class="p">()</span></div></div>


<div class="viewcode-block" id="make_movie"><a class="viewcode-back" href="../../../pymatgen.vis.structure_vtk.html#pymatgen.vis.structure_vtk.make_movie">[docs]</a><span class="k">def</span> <span class="nf">make_movie</span><span class="p">(</span><span class="n">structures</span><span class="p">,</span> <span class="n">output_filename</span><span class="o">=</span><span class="s2">&quot;movie.mp4&quot;</span><span class="p">,</span> <span class="n">zoom</span><span class="o">=</span><span class="mf">1.0</span><span class="p">,</span> <span class="n">fps</span><span class="o">=</span><span class="mi">20</span><span class="p">,</span>
               <span class="n">bitrate</span><span class="o">=</span><span class="s2">&quot;10000k&quot;</span><span class="p">,</span> <span class="n">quality</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
    <span class="sa">r</span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Generate a movie from a sequence of structures using vtk and ffmpeg.</span>

<span class="sd">    Args:</span>
<span class="sd">        structures ([Structure]): sequence of structures</span>
<span class="sd">        output_filename (str): filename for structure output. defaults to</span>
<span class="sd">            movie.mp4</span>
<span class="sd">        zoom (float): A zoom to be applied to the visualizer. Defaults to 1.0.</span>
<span class="sd">        fps (int): Frames per second for the movie. Defaults to 20.</span>
<span class="sd">        bitrate (str): Video bitate.  Defaults to &quot;10000k&quot; (fairly high</span>
<span class="sd">            quality).</span>
<span class="sd">        quality (int): A quality scale. Defaults to 1.</span>
<span class="sd">        \\*\\*kwargs: Any kwargs supported by StructureVis to modify the images</span>
<span class="sd">            generated.</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">vis</span> <span class="o">=</span> <span class="n">StructureVis</span><span class="p">(</span><span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
    <span class="n">vis</span><span class="o">.</span><span class="n">show_help</span> <span class="o">=</span> <span class="kc">False</span>
    <span class="n">vis</span><span class="o">.</span><span class="n">redraw</span><span class="p">()</span>
    <span class="n">vis</span><span class="o">.</span><span class="n">zoom</span><span class="p">(</span><span class="n">zoom</span><span class="p">)</span>
    <span class="n">sigfig</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">math</span><span class="o">.</span><span class="n">floor</span><span class="p">(</span><span class="n">math</span><span class="o">.</span><span class="n">log10</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">structures</span><span class="p">)))</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span>
    <span class="n">filename</span> <span class="o">=</span> <span class="s2">&quot;image{0:0&quot;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="n">sigfig</span><span class="p">)</span> <span class="o">+</span> <span class="s2">&quot;d}.png&quot;</span>
    <span class="k">for</span> <span class="n">i</span><span class="p">,</span> <span class="n">s</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">structures</span><span class="p">):</span>
        <span class="n">vis</span><span class="o">.</span><span class="n">set_structure</span><span class="p">(</span><span class="n">s</span><span class="p">)</span>
        <span class="n">vis</span><span class="o">.</span><span class="n">write_image</span><span class="p">(</span><span class="n">filename</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">i</span><span class="p">),</span> <span class="mi">3</span><span class="p">)</span>
    <span class="n">filename</span> <span class="o">=</span> <span class="s2">&quot;image%0&quot;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="n">sigfig</span><span class="p">)</span> <span class="o">+</span> <span class="s2">&quot;d.png&quot;</span>
    <span class="n">args</span> <span class="o">=</span> <span class="p">[</span><span class="s2">&quot;ffmpeg&quot;</span><span class="p">,</span> <span class="s2">&quot;-y&quot;</span><span class="p">,</span> <span class="s2">&quot;-i&quot;</span><span class="p">,</span> <span class="n">filename</span><span class="p">,</span>
            <span class="s2">&quot;-q:v&quot;</span><span class="p">,</span> <span class="nb">str</span><span class="p">(</span><span class="n">quality</span><span class="p">),</span> <span class="s2">&quot;-r&quot;</span><span class="p">,</span> <span class="nb">str</span><span class="p">(</span><span class="n">fps</span><span class="p">),</span> <span class="s2">&quot;-b:v&quot;</span><span class="p">,</span> <span class="nb">str</span><span class="p">(</span><span class="n">bitrate</span><span class="p">),</span>
            <span class="n">output_filename</span><span class="p">]</span>
    <span class="n">subprocess</span><span class="o">.</span><span class="n">Popen</span><span class="p">(</span><span class="n">args</span><span class="p">)</span></div>


<div class="viewcode-block" id="MultiStructuresVis"><a class="viewcode-back" href="../../../pymatgen.vis.structure_vtk.html#pymatgen.vis.structure_vtk.MultiStructuresVis">[docs]</a><span class="k">class</span> <span class="nc">MultiStructuresVis</span><span class="p">(</span><span class="n">StructureVis</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Visualization for multiple structures.</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">DEFAULT_ANIMATED_MOVIE_OPTIONS</span> <span class="o">=</span> <span class="p">{</span><span class="s1">&#39;time_between_frames&#39;</span><span class="p">:</span> <span class="mf">0.1</span><span class="p">,</span>
                                      <span class="s1">&#39;looping_type&#39;</span><span class="p">:</span> <span class="s1">&#39;restart&#39;</span><span class="p">,</span>
                                      <span class="s1">&#39;number_of_loops&#39;</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span>
                                      <span class="s1">&#39;time_between_loops&#39;</span><span class="p">:</span> <span class="mf">1.0</span><span class="p">}</span>

    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">element_color_mapping</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">show_unit_cell</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span>
                 <span class="n">show_bonds</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">show_polyhedron</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span>
                 <span class="n">poly_radii_tol_factor</span><span class="o">=</span><span class="mf">0.5</span><span class="p">,</span> <span class="n">excluded_bonding_elements</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
                 <span class="n">animated_movie_options</span><span class="o">=</span><span class="n">DEFAULT_ANIMATED_MOVIE_OPTIONS</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Args:</span>
<span class="sd">            element_color_mapping: Optional color mapping for the elements,</span>
<span class="sd">                as a dict of {symbol: rgb tuple}. For example, {&quot;Fe&quot;: (255,</span>
<span class="sd">                123,0), ....} If None is specified, a default based on</span>
<span class="sd">                Jmol&quot;s color scheme is used.</span>
<span class="sd">            show_unit_cell: Set to False to not show the unit cell</span>
<span class="sd">                boundaries. Defaults to True.</span>
<span class="sd">            show_bonds: Set to True to show bonds. Defaults to True.</span>
<span class="sd">            show_polyhedron: Set to True to show polyhedrons. Defaults to</span>
<span class="sd">                False.</span>
<span class="sd">            poly_radii_tol_factor: The polyhedron and bonding code uses the</span>
<span class="sd">                ionic radii of the elements or species to determine if two</span>
<span class="sd">                atoms are bonded. This specifies a tolerance scaling factor</span>
<span class="sd">                such that atoms which are (1 + poly_radii_tol_factor) * sum</span>
<span class="sd">                of ionic radii apart are still considered as bonded.</span>
<span class="sd">            excluded_bonding_elements: List of atom types to exclude from</span>
<span class="sd">                bonding determination. Defaults to an empty list. Useful</span>
<span class="sd">                when trying to visualize a certain atom type in the</span>
<span class="sd">                framework (e.g., Li in a Li-ion battery cathode material).</span>
<span class="sd">            animated_movie_options (): Used for moving.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="n">element_color_mapping</span><span class="o">=</span><span class="n">element_color_mapping</span><span class="p">,</span>
                         <span class="n">show_unit_cell</span><span class="o">=</span><span class="n">show_unit_cell</span><span class="p">,</span>
                         <span class="n">show_bonds</span><span class="o">=</span><span class="n">show_bonds</span><span class="p">,</span> <span class="n">show_polyhedron</span><span class="o">=</span><span class="n">show_polyhedron</span><span class="p">,</span>
                         <span class="n">poly_radii_tol_factor</span><span class="o">=</span><span class="n">poly_radii_tol_factor</span><span class="p">,</span>
                         <span class="n">excluded_bonding_elements</span><span class="o">=</span><span class="n">excluded_bonding_elements</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">warningtxt_actor</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkActor2D</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">infotxt_actor</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkActor2D</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">structures</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="n">style</span> <span class="o">=</span> <span class="n">MultiStructuresInteractorStyle</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">iren</span><span class="o">.</span><span class="n">SetInteractorStyle</span><span class="p">(</span><span class="n">style</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">istruct</span> <span class="o">=</span> <span class="mi">0</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">current_structure</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">set_animated_movie_options</span><span class="p">(</span><span class="n">animated_movie_options</span><span class="o">=</span><span class="n">animated_movie_options</span><span class="p">)</span>

<div class="viewcode-block" id="MultiStructuresVis.set_structures"><a class="viewcode-back" href="../../../pymatgen.vis.structure_vtk.html#pymatgen.vis.structure_vtk.MultiStructuresVis.set_structures">[docs]</a>    <span class="k">def</span> <span class="nf">set_structures</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">structures</span><span class="p">,</span> <span class="n">tags</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Add list of structures to the visualizer.</span>

<span class="sd">        Args:</span>
<span class="sd">            structures (List of Structures):</span>
<span class="sd">            tags (): List of tags.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">structures</span> <span class="o">=</span> <span class="n">structures</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">istruct</span> <span class="o">=</span> <span class="mi">0</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">current_structure</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">structures</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">istruct</span><span class="p">]</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">tags</span> <span class="o">=</span> <span class="n">tags</span> <span class="k">if</span> <span class="n">tags</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span> <span class="k">else</span> <span class="p">[]</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">all_radii</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">all_vis_radii</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="k">for</span> <span class="n">struct</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">structures</span><span class="p">:</span>
            <span class="n">struct_radii</span> <span class="o">=</span> <span class="p">[]</span>
            <span class="n">struct_vis_radii</span> <span class="o">=</span> <span class="p">[]</span>
            <span class="k">for</span> <span class="n">site</span> <span class="ow">in</span> <span class="n">struct</span><span class="p">:</span>
                <span class="n">radius</span> <span class="o">=</span> <span class="mi">0</span>
                <span class="k">for</span> <span class="n">specie</span><span class="p">,</span> <span class="n">occu</span> <span class="ow">in</span> <span class="n">site</span><span class="o">.</span><span class="n">species</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
                    <span class="n">radius</span> <span class="o">+=</span> <span class="n">occu</span> <span class="o">*</span> <span class="p">(</span><span class="n">specie</span><span class="o">.</span><span class="n">ionic_radius</span>
                                      <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">specie</span><span class="p">,</span> <span class="n">Specie</span><span class="p">)</span> <span class="ow">and</span> <span class="n">specie</span><span class="o">.</span><span class="n">ionic_radius</span>
                                      <span class="k">else</span> <span class="n">specie</span><span class="o">.</span><span class="n">average_ionic_radius</span><span class="p">)</span>
                    <span class="n">vis_radius</span> <span class="o">=</span> <span class="mf">0.2</span> <span class="o">+</span> <span class="mf">0.002</span> <span class="o">*</span> <span class="n">radius</span>
                <span class="n">struct_radii</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">radius</span><span class="p">)</span>
                <span class="n">struct_vis_radii</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">vis_radius</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">all_radii</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">struct_radii</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">all_vis_radii</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">struct_vis_radii</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">set_structure</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">current_structure</span><span class="p">,</span> <span class="n">reset_camera</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">to_unit_cell</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span></div>

<div class="viewcode-block" id="MultiStructuresVis.set_structure"><a class="viewcode-back" href="../../../pymatgen.vis.structure_vtk.html#pymatgen.vis.structure_vtk.MultiStructuresVis.set_structure">[docs]</a>    <span class="k">def</span> <span class="nf">set_structure</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">structure</span><span class="p">,</span> <span class="n">reset_camera</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">to_unit_cell</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Add a structure to the visualizer.</span>

<span class="sd">        Args:</span>
<span class="sd">            structure: structure to visualize</span>
<span class="sd">            reset_camera: Set to True to reset the camera to a default</span>
<span class="sd">                determined based on the structure.</span>
<span class="sd">            to_unit_cell: Whether or not to fall back sites into the unit cell.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="n">set_structure</span><span class="p">(</span><span class="n">structure</span><span class="o">=</span><span class="n">structure</span><span class="p">,</span> <span class="n">reset_camera</span><span class="o">=</span><span class="n">reset_camera</span><span class="p">,</span>
                              <span class="n">to_unit_cell</span><span class="o">=</span><span class="n">to_unit_cell</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">apply_tags</span><span class="p">()</span></div>

<div class="viewcode-block" id="MultiStructuresVis.apply_tags"><a class="viewcode-back" href="../../../pymatgen.vis.structure_vtk.html#pymatgen.vis.structure_vtk.MultiStructuresVis.apply_tags">[docs]</a>    <span class="k">def</span> <span class="nf">apply_tags</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Apply tags.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">tags</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="k">for</span> <span class="n">tag</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">tags</span><span class="p">:</span>
            <span class="n">istruct</span> <span class="o">=</span> <span class="n">tag</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;istruct&#39;</span><span class="p">,</span> <span class="s1">&#39;all&#39;</span><span class="p">)</span>
            <span class="k">if</span> <span class="n">istruct</span> <span class="o">!=</span> <span class="s1">&#39;all&#39;</span><span class="p">:</span>
                <span class="k">if</span> <span class="n">istruct</span> <span class="o">!=</span> <span class="bp">self</span><span class="o">.</span><span class="n">istruct</span><span class="p">:</span>
                    <span class="k">continue</span>
            <span class="n">site_index</span> <span class="o">=</span> <span class="n">tag</span><span class="p">[</span><span class="s1">&#39;site_index&#39;</span><span class="p">]</span>
            <span class="n">color</span> <span class="o">=</span> <span class="n">tag</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;color&#39;</span><span class="p">,</span> <span class="p">[</span><span class="mf">0.5</span><span class="p">,</span> <span class="mf">0.5</span><span class="p">,</span> <span class="mf">0.5</span><span class="p">])</span>
            <span class="n">opacity</span> <span class="o">=</span> <span class="n">tag</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;opacity&#39;</span><span class="p">,</span> <span class="mf">0.5</span><span class="p">)</span>
            <span class="k">if</span> <span class="n">site_index</span> <span class="o">==</span> <span class="s1">&#39;unit_cell_all&#39;</span><span class="p">:</span>
                <span class="n">struct_radii</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">all_vis_radii</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">istruct</span><span class="p">]</span>
                <span class="k">for</span> <span class="n">isite</span><span class="p">,</span> <span class="n">site</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">current_structure</span><span class="p">):</span>
                    <span class="n">vis_radius</span> <span class="o">=</span> <span class="mf">1.5</span> <span class="o">*</span> <span class="n">tag</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;radius&#39;</span><span class="p">,</span> <span class="n">struct_radii</span><span class="p">[</span><span class="n">isite</span><span class="p">])</span>
                    <span class="n">tags</span><span class="p">[(</span><span class="n">isite</span><span class="p">,</span> <span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">))]</span> <span class="o">=</span> <span class="p">{</span><span class="s1">&#39;radius&#39;</span><span class="p">:</span> <span class="n">vis_radius</span><span class="p">,</span>
                                                <span class="s1">&#39;color&#39;</span><span class="p">:</span> <span class="n">color</span><span class="p">,</span>
                                                <span class="s1">&#39;opacity&#39;</span><span class="p">:</span> <span class="n">opacity</span><span class="p">}</span>
                <span class="k">continue</span>
            <span class="n">cell_index</span> <span class="o">=</span> <span class="n">tag</span><span class="p">[</span><span class="s1">&#39;cell_index&#39;</span><span class="p">]</span>
            <span class="k">if</span> <span class="s1">&#39;radius&#39;</span> <span class="ow">in</span> <span class="n">tag</span><span class="p">:</span>
                <span class="n">vis_radius</span> <span class="o">=</span> <span class="n">tag</span><span class="p">[</span><span class="s1">&#39;radius&#39;</span><span class="p">]</span>
            <span class="k">elif</span> <span class="s1">&#39;radius_factor&#39;</span> <span class="ow">in</span> <span class="n">tag</span><span class="p">:</span>
                <span class="n">vis_radius</span> <span class="o">=</span> <span class="n">tag</span><span class="p">[</span><span class="s1">&#39;radius_factor&#39;</span><span class="p">]</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">all_vis_radii</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">istruct</span><span class="p">][</span><span class="n">site_index</span><span class="p">]</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">vis_radius</span> <span class="o">=</span> <span class="mf">1.5</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">all_vis_radii</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">istruct</span><span class="p">][</span><span class="n">site_index</span><span class="p">]</span>
            <span class="n">tags</span><span class="p">[(</span><span class="n">site_index</span><span class="p">,</span> <span class="n">cell_index</span><span class="p">)]</span> <span class="o">=</span> <span class="p">{</span><span class="s1">&#39;radius&#39;</span><span class="p">:</span> <span class="n">vis_radius</span><span class="p">,</span>
                                              <span class="s1">&#39;color&#39;</span><span class="p">:</span> <span class="n">color</span><span class="p">,</span>
                                              <span class="s1">&#39;opacity&#39;</span><span class="p">:</span> <span class="n">opacity</span><span class="p">}</span>
        <span class="k">for</span> <span class="n">site_and_cell_index</span><span class="p">,</span> <span class="n">tag_style</span> <span class="ow">in</span> <span class="n">tags</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
            <span class="n">isite</span><span class="p">,</span> <span class="n">cell_index</span> <span class="o">=</span> <span class="n">site_and_cell_index</span>
            <span class="n">site</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">current_structure</span><span class="p">[</span><span class="n">isite</span><span class="p">]</span>
            <span class="k">if</span> <span class="n">cell_index</span> <span class="o">==</span> <span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">):</span>
                <span class="n">coords</span> <span class="o">=</span> <span class="n">site</span><span class="o">.</span><span class="n">coords</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">fcoords</span> <span class="o">=</span> <span class="n">site</span><span class="o">.</span><span class="n">frac_coords</span> <span class="o">+</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">cell_index</span><span class="p">)</span>
                <span class="n">site_image</span> <span class="o">=</span> <span class="n">PeriodicSite</span><span class="p">(</span><span class="n">site</span><span class="o">.</span><span class="n">species</span><span class="p">,</span> <span class="n">fcoords</span><span class="p">,</span>
                                          <span class="bp">self</span><span class="o">.</span><span class="n">current_structure</span><span class="o">.</span><span class="n">lattice</span><span class="p">,</span> <span class="n">to_unit_cell</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span>
                                          <span class="n">coords_are_cartesian</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span>
                                          <span class="n">properties</span><span class="o">=</span><span class="n">site</span><span class="o">.</span><span class="n">properties</span><span class="p">)</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">add_site</span><span class="p">(</span><span class="n">site_image</span><span class="p">)</span>
                <span class="n">coords</span> <span class="o">=</span> <span class="n">site_image</span><span class="o">.</span><span class="n">coords</span>
            <span class="n">vis_radius</span> <span class="o">=</span> <span class="n">tag_style</span><span class="p">[</span><span class="s1">&#39;radius&#39;</span><span class="p">]</span>
            <span class="n">color</span> <span class="o">=</span> <span class="n">tag_style</span><span class="p">[</span><span class="s1">&#39;color&#39;</span><span class="p">]</span>
            <span class="n">opacity</span> <span class="o">=</span> <span class="n">tag_style</span><span class="p">[</span><span class="s1">&#39;opacity&#39;</span><span class="p">]</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">add_partial_sphere</span><span class="p">(</span><span class="n">coords</span><span class="o">=</span><span class="n">coords</span><span class="p">,</span> <span class="n">radius</span><span class="o">=</span><span class="n">vis_radius</span><span class="p">,</span>
                                    <span class="n">color</span><span class="o">=</span><span class="n">color</span><span class="p">,</span> <span class="n">start</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">end</span><span class="o">=</span><span class="mi">360</span><span class="p">,</span>
                                    <span class="n">opacity</span><span class="o">=</span><span class="n">opacity</span><span class="p">)</span></div>

<div class="viewcode-block" id="MultiStructuresVis.set_animated_movie_options"><a class="viewcode-back" href="../../../pymatgen.vis.structure_vtk.html#pymatgen.vis.structure_vtk.MultiStructuresVis.set_animated_movie_options">[docs]</a>    <span class="k">def</span> <span class="nf">set_animated_movie_options</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">animated_movie_options</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Args:</span>
<span class="sd">            animated_movie_options ():</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="n">animated_movie_options</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">animated_movie_options</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">DEFAULT_ANIMATED_MOVIE_OPTIONS</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">animated_movie_options</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">DEFAULT_ANIMATED_MOVIE_OPTIONS</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
            <span class="k">for</span> <span class="n">key</span> <span class="ow">in</span> <span class="n">animated_movie_options</span><span class="p">:</span>
                <span class="k">if</span> <span class="n">key</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">DEFAULT_ANIMATED_MOVIE_OPTIONS</span><span class="o">.</span><span class="n">keys</span><span class="p">():</span>
                    <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s1">&#39;Wrong option for animated movie&#39;</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">animated_movie_options</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="n">animated_movie_options</span><span class="p">)</span></div>

<div class="viewcode-block" id="MultiStructuresVis.display_help"><a class="viewcode-back" href="../../../pymatgen.vis.structure_vtk.html#pymatgen.vis.structure_vtk.MultiStructuresVis.display_help">[docs]</a>    <span class="k">def</span> <span class="nf">display_help</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Display the help for various keyboard shortcuts.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">helptxt</span> <span class="o">=</span> <span class="p">[</span><span class="s2">&quot;h : Toggle help&quot;</span><span class="p">,</span>
                   <span class="s2">&quot;A/a, B/b or C/c : Increase/decrease cell by one a,&quot;</span>
                   <span class="s2">&quot; b or c unit vector&quot;</span><span class="p">,</span> <span class="s2">&quot;# : Toggle showing of polyhedrons&quot;</span><span class="p">,</span>
                   <span class="s2">&quot;-: Toggle showing of bonds&quot;</span><span class="p">,</span> <span class="s2">&quot;r : Reset camera direction&quot;</span><span class="p">,</span>
                   <span class="s2">&quot;[/]: Decrease or increase poly_radii_tol_factor &quot;</span>
                   <span class="s2">&quot;by 0.05. Value = &quot;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">poly_radii_tol_factor</span><span class="p">),</span>
                   <span class="s2">&quot;Up/Down: Rotate view along Up direction by 90 &quot;</span>
                   <span class="s2">&quot;clockwise/anticlockwise&quot;</span><span class="p">,</span>
                   <span class="s2">&quot;Left/right: Rotate view along camera direction by &quot;</span>
                   <span class="s2">&quot;90 clockwise/anticlockwise&quot;</span><span class="p">,</span> <span class="s2">&quot;s: Save view to image.png&quot;</span><span class="p">,</span>
                   <span class="s2">&quot;o: Orthogonalize structure&quot;</span><span class="p">,</span>
                   <span class="s2">&quot;n: Move to next structure&quot;</span><span class="p">,</span>
                   <span class="s2">&quot;p: Move to previous structure&quot;</span><span class="p">,</span>
                   <span class="s2">&quot;m: Animated movie of the structures&quot;</span><span class="p">]</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">helptxt_mapper</span><span class="o">.</span><span class="n">SetInput</span><span class="p">(</span><span class="s2">&quot;</span><span class="se">\n</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">helptxt</span><span class="p">))</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">helptxt_actor</span><span class="o">.</span><span class="n">SetPosition</span><span class="p">(</span><span class="mi">10</span><span class="p">,</span> <span class="mi">10</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">helptxt_actor</span><span class="o">.</span><span class="n">VisibilityOn</span><span class="p">()</span></div>

<div class="viewcode-block" id="MultiStructuresVis.display_warning"><a class="viewcode-back" href="../../../pymatgen.vis.structure_vtk.html#pymatgen.vis.structure_vtk.MultiStructuresVis.display_warning">[docs]</a>    <span class="k">def</span> <span class="nf">display_warning</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">warning</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Args:</span>
<span class="sd">            warning (str): Warning</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">warningtxt_mapper</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkTextMapper</span><span class="p">()</span>
        <span class="n">tprops</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">warningtxt_mapper</span><span class="o">.</span><span class="n">GetTextProperty</span><span class="p">()</span>
        <span class="n">tprops</span><span class="o">.</span><span class="n">SetFontSize</span><span class="p">(</span><span class="mi">14</span><span class="p">)</span>
        <span class="n">tprops</span><span class="o">.</span><span class="n">SetFontFamilyToTimes</span><span class="p">()</span>
        <span class="n">tprops</span><span class="o">.</span><span class="n">SetColor</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span>
        <span class="n">tprops</span><span class="o">.</span><span class="n">BoldOn</span><span class="p">()</span>
        <span class="n">tprops</span><span class="o">.</span><span class="n">SetJustificationToRight</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">warningtxt</span> <span class="o">=</span> <span class="s2">&quot;WARNING : </span><span class="si">{}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">warning</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">warningtxt_actor</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkActor2D</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">warningtxt_actor</span><span class="o">.</span><span class="n">VisibilityOn</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">warningtxt_actor</span><span class="o">.</span><span class="n">SetMapper</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">warningtxt_mapper</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">ren</span><span class="o">.</span><span class="n">AddActor</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">warningtxt_actor</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">warningtxt_mapper</span><span class="o">.</span><span class="n">SetInput</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">warningtxt</span><span class="p">)</span>
        <span class="n">winsize</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">ren_win</span><span class="o">.</span><span class="n">GetSize</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">warningtxt_actor</span><span class="o">.</span><span class="n">SetPosition</span><span class="p">(</span><span class="n">winsize</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">-</span> <span class="mi">10</span><span class="p">,</span> <span class="mi">10</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">warningtxt_actor</span><span class="o">.</span><span class="n">VisibilityOn</span><span class="p">()</span></div>

<div class="viewcode-block" id="MultiStructuresVis.erase_warning"><a class="viewcode-back" href="../../../pymatgen.vis.structure_vtk.html#pymatgen.vis.structure_vtk.MultiStructuresVis.erase_warning">[docs]</a>    <span class="k">def</span> <span class="nf">erase_warning</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Remove warnings.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">warningtxt_actor</span><span class="o">.</span><span class="n">VisibilityOff</span><span class="p">()</span></div>

<div class="viewcode-block" id="MultiStructuresVis.display_info"><a class="viewcode-back" href="../../../pymatgen.vis.structure_vtk.html#pymatgen.vis.structure_vtk.MultiStructuresVis.display_info">[docs]</a>    <span class="k">def</span> <span class="nf">display_info</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">info</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Args:</span>
<span class="sd">            info (str): Information.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">infotxt_mapper</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkTextMapper</span><span class="p">()</span>
        <span class="n">tprops</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">infotxt_mapper</span><span class="o">.</span><span class="n">GetTextProperty</span><span class="p">()</span>
        <span class="n">tprops</span><span class="o">.</span><span class="n">SetFontSize</span><span class="p">(</span><span class="mi">14</span><span class="p">)</span>
        <span class="n">tprops</span><span class="o">.</span><span class="n">SetFontFamilyToTimes</span><span class="p">()</span>
        <span class="n">tprops</span><span class="o">.</span><span class="n">SetColor</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
        <span class="n">tprops</span><span class="o">.</span><span class="n">BoldOn</span><span class="p">()</span>
        <span class="n">tprops</span><span class="o">.</span><span class="n">SetVerticalJustificationToTop</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">infotxt</span> <span class="o">=</span> <span class="s2">&quot;INFO : </span><span class="si">{}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">info</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">infotxt_actor</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkActor2D</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">infotxt_actor</span><span class="o">.</span><span class="n">VisibilityOn</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">infotxt_actor</span><span class="o">.</span><span class="n">SetMapper</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">infotxt_mapper</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">ren</span><span class="o">.</span><span class="n">AddActor</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">infotxt_actor</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">infotxt_mapper</span><span class="o">.</span><span class="n">SetInput</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">infotxt</span><span class="p">)</span>
        <span class="n">winsize</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">ren_win</span><span class="o">.</span><span class="n">GetSize</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">infotxt_actor</span><span class="o">.</span><span class="n">SetPosition</span><span class="p">(</span><span class="mi">10</span><span class="p">,</span> <span class="n">winsize</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">-</span> <span class="mi">10</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">infotxt_actor</span><span class="o">.</span><span class="n">VisibilityOn</span><span class="p">()</span></div>

<div class="viewcode-block" id="MultiStructuresVis.erase_info"><a class="viewcode-back" href="../../../pymatgen.vis.structure_vtk.html#pymatgen.vis.structure_vtk.MultiStructuresVis.erase_info">[docs]</a>    <span class="k">def</span> <span class="nf">erase_info</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Erase all info.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">infotxt_actor</span><span class="o">.</span><span class="n">VisibilityOff</span><span class="p">()</span></div></div>


<div class="viewcode-block" id="MultiStructuresInteractorStyle"><a class="viewcode-back" href="../../../pymatgen.vis.structure_vtk.html#pymatgen.vis.structure_vtk.MultiStructuresInteractorStyle">[docs]</a><span class="k">class</span> <span class="nc">MultiStructuresInteractorStyle</span><span class="p">(</span><span class="n">StructureInteractorStyle</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Interactor for MultiStructureVis.</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">parent</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Args:</span>
<span class="sd">            parent ():</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">StructureInteractorStyle</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">parent</span><span class="o">=</span><span class="n">parent</span><span class="p">)</span>

<div class="viewcode-block" id="MultiStructuresInteractorStyle.keyPressEvent"><a class="viewcode-back" href="../../../pymatgen.vis.structure_vtk.html#pymatgen.vis.structure_vtk.MultiStructuresInteractorStyle.keyPressEvent">[docs]</a>    <span class="k">def</span> <span class="nf">keyPressEvent</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">obj</span><span class="p">,</span> <span class="n">event</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Args:</span>
<span class="sd">            obj ():</span>
<span class="sd">            event ():</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">parent</span> <span class="o">=</span> <span class="n">obj</span><span class="o">.</span><span class="n">GetCurrentRenderer</span><span class="p">()</span><span class="o">.</span><span class="n">parent</span>
        <span class="n">sym</span> <span class="o">=</span> <span class="n">parent</span><span class="o">.</span><span class="n">iren</span><span class="o">.</span><span class="n">GetKeySym</span><span class="p">()</span>

        <span class="k">if</span> <span class="n">sym</span> <span class="o">==</span> <span class="s2">&quot;n&quot;</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">parent</span><span class="o">.</span><span class="n">istruct</span> <span class="o">==</span> <span class="nb">len</span><span class="p">(</span><span class="n">parent</span><span class="o">.</span><span class="n">structures</span><span class="p">)</span> <span class="o">-</span> <span class="mi">1</span><span class="p">:</span>
                <span class="n">parent</span><span class="o">.</span><span class="n">display_warning</span><span class="p">(</span><span class="s1">&#39;LAST STRUCTURE&#39;</span><span class="p">)</span>
                <span class="n">parent</span><span class="o">.</span><span class="n">ren_win</span><span class="o">.</span><span class="n">Render</span><span class="p">()</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">parent</span><span class="o">.</span><span class="n">istruct</span> <span class="o">+=</span> <span class="mi">1</span>
                <span class="n">parent</span><span class="o">.</span><span class="n">current_structure</span> <span class="o">=</span> <span class="n">parent</span><span class="o">.</span><span class="n">structures</span><span class="p">[</span><span class="n">parent</span><span class="o">.</span><span class="n">istruct</span><span class="p">]</span>
                <span class="n">parent</span><span class="o">.</span><span class="n">set_structure</span><span class="p">(</span><span class="n">parent</span><span class="o">.</span><span class="n">current_structure</span><span class="p">,</span> <span class="n">reset_camera</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">to_unit_cell</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
                <span class="n">parent</span><span class="o">.</span><span class="n">erase_warning</span><span class="p">()</span>
                <span class="n">parent</span><span class="o">.</span><span class="n">ren_win</span><span class="o">.</span><span class="n">Render</span><span class="p">()</span>
        <span class="k">elif</span> <span class="n">sym</span> <span class="o">==</span> <span class="s2">&quot;p&quot;</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">parent</span><span class="o">.</span><span class="n">istruct</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
                <span class="n">parent</span><span class="o">.</span><span class="n">display_warning</span><span class="p">(</span><span class="s1">&#39;FIRST STRUCTURE&#39;</span><span class="p">)</span>
                <span class="n">parent</span><span class="o">.</span><span class="n">ren_win</span><span class="o">.</span><span class="n">Render</span><span class="p">()</span>
            <span class="k">else</span><span class="p">:</span>

                <span class="n">parent</span><span class="o">.</span><span class="n">istruct</span> <span class="o">-=</span> <span class="mi">1</span>
                <span class="n">parent</span><span class="o">.</span><span class="n">current_structure</span> <span class="o">=</span> <span class="n">parent</span><span class="o">.</span><span class="n">structures</span><span class="p">[</span><span class="n">parent</span><span class="o">.</span><span class="n">istruct</span><span class="p">]</span>
                <span class="n">parent</span><span class="o">.</span><span class="n">set_structure</span><span class="p">(</span><span class="n">parent</span><span class="o">.</span><span class="n">current_structure</span><span class="p">,</span> <span class="n">reset_camera</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">to_unit_cell</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
                <span class="n">parent</span><span class="o">.</span><span class="n">erase_warning</span><span class="p">()</span>
                <span class="n">parent</span><span class="o">.</span><span class="n">ren_win</span><span class="o">.</span><span class="n">Render</span><span class="p">()</span>
        <span class="k">elif</span> <span class="n">sym</span> <span class="o">==</span> <span class="s2">&quot;m&quot;</span><span class="p">:</span>
            <span class="n">parent</span><span class="o">.</span><span class="n">istruct</span> <span class="o">=</span> <span class="mi">0</span>
            <span class="n">parent</span><span class="o">.</span><span class="n">current_structure</span> <span class="o">=</span> <span class="n">parent</span><span class="o">.</span><span class="n">structures</span><span class="p">[</span><span class="n">parent</span><span class="o">.</span><span class="n">istruct</span><span class="p">]</span>
            <span class="n">parent</span><span class="o">.</span><span class="n">set_structure</span><span class="p">(</span><span class="n">parent</span><span class="o">.</span><span class="n">current_structure</span><span class="p">,</span> <span class="n">reset_camera</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">to_unit_cell</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
            <span class="n">parent</span><span class="o">.</span><span class="n">erase_warning</span><span class="p">()</span>
            <span class="n">parent</span><span class="o">.</span><span class="n">ren_win</span><span class="o">.</span><span class="n">Render</span><span class="p">()</span>
            <span class="n">nloops</span> <span class="o">=</span> <span class="n">parent</span><span class="o">.</span><span class="n">animated_movie_options</span><span class="p">[</span><span class="s1">&#39;number_of_loops&#39;</span><span class="p">]</span>
            <span class="n">tstep</span> <span class="o">=</span> <span class="n">parent</span><span class="o">.</span><span class="n">animated_movie_options</span><span class="p">[</span><span class="s1">&#39;time_between_frames&#39;</span><span class="p">]</span>
            <span class="n">tloops</span> <span class="o">=</span> <span class="n">parent</span><span class="o">.</span><span class="n">animated_movie_options</span><span class="p">[</span><span class="s1">&#39;time_between_loops&#39;</span><span class="p">]</span>
            <span class="k">if</span> <span class="n">parent</span><span class="o">.</span><span class="n">animated_movie_options</span><span class="p">[</span><span class="s1">&#39;looping_type&#39;</span><span class="p">]</span> <span class="o">==</span> <span class="s1">&#39;restart&#39;</span><span class="p">:</span>
                <span class="n">loop_istructs</span> <span class="o">=</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">parent</span><span class="o">.</span><span class="n">structures</span><span class="p">))</span>
            <span class="k">elif</span> <span class="n">parent</span><span class="o">.</span><span class="n">animated_movie_options</span><span class="p">[</span><span class="s1">&#39;looping_type&#39;</span><span class="p">]</span> <span class="o">==</span> <span class="s1">&#39;palindrome&#39;</span><span class="p">:</span>
                <span class="n">loop_istructs</span> <span class="o">=</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">parent</span><span class="o">.</span><span class="n">structures</span><span class="p">))</span> <span class="o">+</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">parent</span><span class="o">.</span><span class="n">structures</span><span class="p">)</span> <span class="o">-</span> <span class="mi">2</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">)</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s1">&#39;&quot;looping_type&quot; should be &quot;restart&quot; or &quot;palindrome&quot;&#39;</span><span class="p">)</span>
            <span class="k">for</span> <span class="n">iloop</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">nloops</span><span class="p">):</span>
                <span class="k">for</span> <span class="n">istruct</span> <span class="ow">in</span> <span class="n">loop_istructs</span><span class="p">:</span>
                    <span class="n">time</span><span class="o">.</span><span class="n">sleep</span><span class="p">(</span><span class="n">tstep</span><span class="p">)</span>
                    <span class="n">parent</span><span class="o">.</span><span class="n">istruct</span> <span class="o">=</span> <span class="n">istruct</span>
                    <span class="n">parent</span><span class="o">.</span><span class="n">current_structure</span> <span class="o">=</span> <span class="n">parent</span><span class="o">.</span><span class="n">structures</span><span class="p">[</span><span class="n">parent</span><span class="o">.</span><span class="n">istruct</span><span class="p">]</span>
                    <span class="n">parent</span><span class="o">.</span><span class="n">set_structure</span><span class="p">(</span><span class="n">parent</span><span class="o">.</span><span class="n">current_structure</span><span class="p">,</span> <span class="n">reset_camera</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">to_unit_cell</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
                    <span class="n">parent</span><span class="o">.</span><span class="n">display_info</span><span class="p">(</span><span class="s1">&#39;Animated movie : structure </span><span class="si">{:d}</span><span class="s1">/</span><span class="si">{:d}</span><span class="s1"> &#39;</span>
                                        <span class="s1">&#39;(loop </span><span class="si">{:d}</span><span class="s1">/</span><span class="si">{:d}</span><span class="s1">)&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">istruct</span> <span class="o">+</span> <span class="mi">1</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="n">parent</span><span class="o">.</span><span class="n">structures</span><span class="p">),</span>
                                                                  <span class="n">iloop</span> <span class="o">+</span> <span class="mi">1</span><span class="p">,</span> <span class="n">nloops</span><span class="p">))</span>
                    <span class="n">parent</span><span class="o">.</span><span class="n">ren_win</span><span class="o">.</span><span class="n">Render</span><span class="p">()</span>
                <span class="n">time</span><span class="o">.</span><span class="n">sleep</span><span class="p">(</span><span class="n">tloops</span><span class="p">)</span>
            <span class="n">parent</span><span class="o">.</span><span class="n">erase_info</span><span class="p">()</span>
            <span class="n">parent</span><span class="o">.</span><span class="n">display_info</span><span class="p">(</span><span class="s1">&#39;Ended animated movie ...&#39;</span><span class="p">)</span>
            <span class="n">parent</span><span class="o">.</span><span class="n">ren_win</span><span class="o">.</span><span class="n">Render</span><span class="p">()</span>

        <span class="n">StructureInteractorStyle</span><span class="o">.</span><span class="n">keyPressEvent</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">obj</span><span class="p">,</span> <span class="n">event</span><span class="p">)</span></div></div>
</pre></div>

            <div class="clearer"></div>
          </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="nav-item nav-item-0"><a href="../../../index.html">pymatgen 2020.7.3 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="../../index.html" >Module code</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="../../pymatgen.html" >pymatgen</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href="">pymatgen.vis.structure_vtk</a></li> 
      </ul>
    </div>

    <div class="footer" role="contentinfo">
        &#169; Copyright 2011, Pymatgen Development Team.
      Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 3.1.2.
    </div>
<div class="footer">This page uses <a href="http://analytics.google.com/">
Google Analytics</a> to collect statistics. You can disable it by blocking
the JavaScript coming from www.google-analytics.com.
<script type="text/javascript">
  (function() {
    var ga = document.createElement('script');
    ga.src = ('https:' == document.location.protocol ?
              'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    ga.setAttribute('async', 'true');
    document.documentElement.firstChild.appendChild(ga);
  })();
</script>
</div>

  </body>
</html>